LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C double to unsigned long long Conversion with mingw32 (https://www.linuxquestions.org/questions/programming-9/c-double-to-unsigned-long-long-conversion-with-mingw32-850182/)

random0 12-14-2010 10:44 AM

C double to unsigned long long Conversion with mingw32
 
The following line is not working for me under mingw32.

Code:

printf("%.0f == %llu\n", 45252301458.0, (unsigned long long)(45252301458.0));
The output is:

Quote:

45252301458 == 2302628498
This is clearly incorrect. 64 bits is more than enough to represent such an integer, so why is it failing? Can I work around this?

Thanks.

theNbomr 12-15-2010 09:53 AM

Are you sure that your compiler treats 'unsigned long long' as a 64 bit integer? Does printf() support 'long long'? Try splitting the 64-bit integer into two 32-bit integers, and try printf()ing those independently.

--- rod.


All times are GMT -5. The time now is 12:18 PM.