This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author nvutri
Recipients nvutri
Date 2017-04-07.04:02:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1491537725.94.0.500502995113.issue30009@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2017-04-07 04:02:05nvutrisetrecipients: + nvutri
2017-04-07 04:02:05nvutrisetmessageid: <1491537725.94.0.500502995113.issue30009@psf.upfronthosting.co.za>
2017-04-07 04:02:05nvutrilinkissue30009 messages
2017-04-07 04:02:05nvutricreate