Strange division results in python 3 -


i think there inconsistency in division operation, not sure.

in following code expect either a//c 100.0, or b//c -99.0.

a = 1.0 b = -1.0 c = 0.01  print (a/c) print (a//c) print (b/c) print (b//c) 

gives:

100.0 99.0 -100.0 -100.0 

thanks

this due way floating point numbers represented. it's not true 1.0 100 times 0.01 (as far floating points represented internally). operator // performs division , floors result may internally number less 100.0 , leads being floored 99.0.

furthermore, python 3.x uses a different approach showing floating point number compared python 2.x. means result of 1.0 / 0.01, although internally less 100.0, displayed 100.0 because algorithm determined number close enough 100.0 considered equal 100.0. why 1.0 / 0.01 shown 100.0 though may not represented internally number.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -