+ 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

24th Mar 2019, 12:24 PM
Saksham Jain
Saksham Jain - avatar
10 Answers
+ 4
Saksham Jain Search for IEEE 754, that's where it comes from.
24th Mar 2019, 12:41 PM
Luis SepĂșlveda
Luis SepĂșlveda - avatar
+ 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).
24th Mar 2019, 12:33 PM
Anna
Anna - avatar
+ 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
24th Mar 2019, 12:50 PM
Anna
Anna - avatar
+ 3
Anna I want to know behind the scene what is really happening so it outputs -0.0.. SERIOUSLY,WHY in python there is a thing like -0.0 Never saw this thing in java
24th Mar 2019, 12:36 PM
Saksham Jain
Saksham Jain - avatar
+ 3
Is it nonsense? 0 is just as not negative as it is not positive.
24th Mar 2019, 1:06 PM
HonFu
HonFu - avatar
+ 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,
24th Mar 2019, 1:30 PM
Saksham Jain
Saksham Jain - avatar
+ 3
⚡Prometheus ⚡ this occurred to me in python not in Java,search IEEE 754 MAYBE IT IS MADE TO BE AMBIGOUS?!!!!
25th Mar 2019, 3:34 AM
Saksham Jain
Saksham Jain - avatar
+ 2
Anna I also thought that but How it might create total nonsense?
24th Mar 2019, 1:00 PM
Saksham Jain
Saksham Jain - avatar
+ 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.
24th Mar 2019, 1:43 PM
HonFu
HonFu - avatar
+ 1
It's a coding convention I guess?
24th Mar 2019, 4:18 PM
👑 Prometheus 🇾🇬
👑 Prometheus 🇾🇬 - avatar