`equal(0.3, 0.2 + 0.1); // true` how is this wizardry possible?
addendum: why are obviously rhetorical questions are taken so literally here?
11–20 of 227 posts
`equal(0.3, 0.2 + 0.1); // true` how is this wizardry possible?
addendum: why are obviously rhetorical questions are taken so literally here?
Umm… that’s quite the goal.
I’ll stick with deprecated Python.
All in all: quite a solid attempt. I'll give you 8/10 for the design of this. The way you sketched this out in C using macros is really elegant. This actually looks like good code. Would I use it? It's a new language and I like C already. It could help people learn C and think about language design. Since the way you've done this is very clear.
I'm reminded of the guy who did #define BEGIN { #define END } and a whole bunch of other macro-larkey just to make C look more like Pascal. Only then would he deign to code in it.
`equal(0.3, 0.2 + 0.1); // true` how is this wizardry possible?
static int pretty_float_equal (float a, float b) { return fabsf(a - b) `equal(0.3, 0.2 + 0.1); // true` how is this wizardry possible?
`equal(0.3, 0.2 + 0.1); // true` how is this wizardry possible?
static int pretty_float_equal (float a, float b) { return fabsf(a - b)
So it’s https://docs.python.org/library/math.html#math.isclose`equal(0.3, 0.2 + 0.1); // true` how is this wizardry possible?
it uses absolute difference epsilon equality ('close enough to be considered equal'): static int pretty_float_equal (float a, float b) { return fabsf(a - b)
`equal(0.3, 0.2 + 0.1); // true` how is this wizardry possible?
Is What Every Computer Scientist Should Know About Floating-Point Arithmetic wrong ??!! addendum: why are obviously rhetorical questions are taken so literally here?
Earlier quoted context omitted.
it uses absolute difference epsilon equality ('close enough to be considered equal'): static int pretty_float_equal (float a, float b) { return fabsf(a - b)
This is wrong code. It only works somewhat correctly when a and b around 1.