3 ms·
Floating point numbers are dangerous but in 2023 we should find a way to improve the side effects. Playing with Python3: >>> +0.0==-0.0 True The C in GCC bel
by wslh 4y ago
Floating point numbers are dangerous but in 2023 we should find a way to improve the side effects.
Playing with Python3:
>>> +0.0==-0.0
True
The C in GCC below also returns 1:
#include <stdio.h>
int main()
{
float a = +0.0;
float b = -0.0;
printf("%d\n", a == b);
}
- Y_Y 4y agoErlang too, now and in the future will say that minuszero==zero, it's a different more specific operator that's changing. You'll get the same in python with >>> -0. is 0. False
- Kwpolska 4y agoThe `is` operator is checking object identity by comparing addresses. It is useless, although it may sometimes produce reasonable-looking results due to optimisations. Python 3.11 gives me this: >>> -0 is 0 <stdin>:1: SyntaxWarning: "is" with a literal. Did you mean "=="? True Because (a) -0 is an integer, and there is only one integer zero, (b) small numbers have only one instance in memory as an optimization.