New submission from Tri Nguyen:

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

----------
components: Library (Lib)
files: int_bug.py
messages: 291249
nosy: nvutri
priority: normal
severity: normal
status: open
title: Integer conversion failure
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file46783/int_bug.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30009>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to