[issue3024] Integer conversion inconsistent

2008-06-01 Thread Raymond Hettinger
Raymond Hettinger <[EMAIL PROTECTED]> added the comment: This is exactly what int() is supposed to do. For other kinds of rounding, look at round(), math.floor(), math.ceil(), and many rounding options in the decimal module: from decimal import Decimal >>> Decimal('-23.15').to_integral(ROUND_

[issue3024] Integer conversion inconsistent

2008-06-01 Thread Martin v. Löwis
Martin v. Löwis <[EMAIL PROTECTED]> added the comment: I see. There is no such thing as a "correct" conversion from real numbers to integer numbers. Instead, there are various approaches, called "truncating", "rounding", "flooring", and "ceiling". Python's default conversion is truncation, and it

[issue3024] Integer conversion inconsistent

2008-06-01 Thread Razvan Cosma
Razvan Cosma <[EMAIL PROTECTED]> added the comment: Sorry for not writing completely above - python does neither, it rounds to the integer closest to zero ___ Python tracker <[EMAIL PROTECTED]> ___

[issue3024] Integer conversion inconsistent

2008-06-01 Thread Razvan Cosma
Razvan Cosma <[EMAIL PROTECTED]> added the comment: Hello, As far as I know, the correct conversion is to either round to the nearest, or to the smaller integer, but not both. ___ Python tracker <[EMAIL PROTECTED]> __

[issue3024] Integer conversion inconsistent

2008-06-01 Thread Martin v. Löwis
Martin v. Löwis <[EMAIL PROTECTED]> added the comment: I don't see any problem with that result? Why do you consider the result incorrect, and what "correct" result would you have inspected instead? Notice that int conversion of floats truncates them, by definition. -- nosy: +loewis __

[issue3024] Integer conversion inconsistent

2008-06-01 Thread Razvan Cosma
New submission from Razvan Cosma <[EMAIL PROTECTED]>: This issue is probably older than I am, and was amazed to discover it in python: Python 2.5.2 (r252:60911, May 7 2008, 15:19:09) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 >>> int(float("-23.15")) -23 >>> int(float("-23.65")) -23 >>> int(f