+ 6
-0 weird output python
check the code,i actually want to know what is causing this,behind the scenes .... https://code.sololearn.com/cy45HD3XGfe3/?ref=app
10 Respuestas
+ 4
Saksham Jain Search for IEEE 754, that's where it comes from.
+ 11
0/x = 0 (unless x == 0) and the result of a division will always be a float (0.0). As the divisor is negative, the result will also be negative, so the result is -0.0 (-0.0 and 0.0 are equivalent in python, you can check that with 0/-1 == 0, which will be True).
+ 7
Saksham Jain My guess is that it's more efficient to calculate a/b and put a minus in front of the result in case exctly one of the operands is negative, but that might be total nonsense... I'll ask Guido van Rossum if I'll ever meet him
+ 3
Is it nonsense?
0 is just as not negative as it is not positive.
+ 3
HonFu ya ,I agree that 0 is just as non negative as it is not positive but you don't write 45 as +45
You write -45 as -45 ,so if we use - we mean it is negative,
+ 3
⚡Prometheus ⚡ this occurred to me in python not in Java,search IEEE 754 MAYBE IT IS MADE TO BE AMBIGOUS?!!!!
+ 2
Anna I also thought that but How it might create total nonsense?
+ 1
It's just a convention, though, so no need to worry about how Python writes it as long as the result's the same.
+ 1
It's a coding convention I guess?