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

后端 未结 7 1559
-上瘾入骨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:06

    One more "works on my machine" on Ubuntu with gcc version 4.3.2.

    $ ./a.out
    1.000000
    1.000000
    

    I do get a couple of warnings when I compile, though.

    $ gcc -lm round.c
    round.c: In function ‘main’:
    round.c:11: warning: incompatible implicit declaration of built-in function ‘roundf’
    round.c:12: warning: incompatible implicit declaration of built-in function ‘round’
    

提交回复
热议问题