[issue36934] C API Function PyLong_AsDouble Returning Wrong Value

2019-05-15 Thread Tim Peters
Tim Peters added the comment: It sounds like you need to read an introduction (any!) to computer floating-point formats. The relevant part in the output you showed is this: mant_dig=53 As on almost other current machines, your platform's floating point format is restricted to 53 bits of

[issue36934] C API Function PyLong_AsDouble Returning Wrong Value

2019-05-15 Thread Farhan Sajjad
Farhan Sajjad added the comment: Maybe I need to go back and understand why this loss of precision is taking place for the int->float conversion, and why for certain numbers. Also, it does not work in Python 2. Please disregard the previous message. -- resolution: -> not a bug

[issue36934] C API Function PyLong_AsDouble Returning Wrong Value

2019-05-15 Thread Farhan Sajjad
Farhan Sajjad added the comment: Thanks for your input Tim. Here is what I understand: 1. In Python 3, int can be arbitrarily large. 2. C double data type can hold very large numbers, and the number tested here is quite small compared to the max. It even fits fine in a long long int. 3. Quite

[issue36934] C API Function PyLong_AsDouble Returning Wrong Value

2019-05-15 Thread Tim Peters
Tim Peters added the comment: Note that this pure Python gives the same result: >>> "%.0f" % float(1639873214337061279) '1639873214337061376' That's not surprising: int -> float conversion is limited to the precision of a Python float, which is a C double, which is almost certainly just 53

[issue36934] C API Function PyLong_AsDouble Returning Wrong Value

2019-05-15 Thread Farhan Sajjad
New submission from Farhan Sajjad : Found this rather obscure behavior where certain 64 bit numbers are changing (probably losing precision somewhere down the call chain) if converted from PyLong to double using the PyLong_AsDouble C API function. TO REPRODUCE: #define __SIZEOF_STRS__ 512