Message291249
This code below shows a situation when Python int() library would return a value of int(1.0) -> 0.0
---------------CODE----------------------------
CHANGES = [1.00, 0.50, 0.25, 0.10, 0.05, 0.01]
# This code was originally to solve the least number of changes needed.
# However, in an attempt to solve this. A bug is found.
def get_change(R):
for change in CHANGES:
# This division and int() is where failure is happening
num = int(R / change)
# This printing line shows the failure.
print 'int(%s)\t = %s' % (R / change, num)
R = R - num * change
print 'R = %s' % R
get_change(4.01)
-------------OUTPUT----------------------
int(4.01) = 4
int(0.02) = 0
int(0.04) = 0
int(0.1) = 0
int(0.2) = 0
int(1.0) = 0 # This should be 1, right?
R = 0.01 |
|
Date |
User |
Action |
Args |
2017-04-07 04:02:05 | nvutri | set | recipients:
+ nvutri |
2017-04-07 04:02:05 | nvutri | set | messageid: <1491537725.94.0.500502995113.issue30009@psf.upfronthosting.co.za> |
2017-04-07 04:02:05 | nvutri | link | issue30009 messages |
2017-04-07 04:02:05 | nvutri | create | |
|