+ 6

int() issue

Why >>> 4.9 - int(4.9) == 0.9000000000000004 and not 4.9 - int(4.9) == 0.9 ..?

1st Jul 2017, 3:32 AM
_SneYC's
_SneYC's - avatar
6 odpowiedzi
+ 11
https://docs.python.org/2/tutorial/floatingpoint.html
1st Jul 2017, 3:37 AM
Hatsy Rei
Hatsy Rei - avatar
+ 10
When we deal with floating point arithmetic with high number of decimal values, equality shouldn't be used. You will want to compare your value with a range of acceptable values, and this can be done by introducing epsilons. That said, this isn't always the case. It depends on the nature of the issue you are dealing with. https://stackoverflow.com/questions/2729637/does-epsilon-really-guarantees-anything-in-floating-point-computations
1st Jul 2017, 4:26 AM
Hatsy Rei
Hatsy Rei - avatar
+ 7
@Hatsy: That book available on the link you provided seems it may be very informative. Sigh.. Added to the reading list 😦 http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
1st Jul 2017, 5:18 AM
jay
jay - avatar
+ 6
Python isnt the best calculator. For example. 1/3+2/3=1.0000000000000000001 not 1 has it does 0.333333333333+0.666666666667
1st Jul 2017, 3:51 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 5
Is there anyway ti remove effect
1st Jul 2017, 4:19 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 4
Oh I see.. thx
1st Jul 2017, 3:40 AM
_SneYC's
_SneYC's - avatar