How am I incorrectly using the round() function in C?

后端 未结 7 1523
-上瘾入骨i
-上瘾入骨i 2021-02-08 21:42

I\'m getting unexpected results from the round() and roundf() functions in the math.h library. Here is the sample code:

#         


        
7条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-08 22:11

    When I compile and run this exact code (under gcc on cygwin) I get:

    $ ./a.exe
    1.000000
    1.000000
    

    How new is your compiler? A compiler bug is all I can think of, as gcc -Wall gives no warnings either.

    To add some further information this forum thread seems to show changing compiler to a newer version fixes it. If this doesn't work for you you'll need to give more details of compiler and OS, but given this seems to work for other people on three different platforms looks like your compiler is at fault.

提交回复
热议问题