rounding numbers in gcc ?

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Liberty Young
Date:  
Subject: rounding numbers in gcc ?
How can i round numbers using standard c code?

in gcc-2.96 (and gcc-3.04) from a Mandrake 8.2 box, the following won't
work:

#include <math.h>
#include <stdio.h>

int main () {
printf(" 1.9 rounded is %f\n", roundf(1.9)/*or round(1.9)*/ );
printf(" 1.4 rounded is %f\n", roundf(1.4)/*ditto*/ );
return 0;
}


gcc -Wall -D_GNU_SOURCE -D_ISOC99_SOURCE foo.c -o foo


returns
/home/liberty/tmp/ccQqyMJ7.o: In function `main':
/home/liberty/tmp/ccQqyMJ7.o(.text+0x12): undefined reference to
`roundf'
/home/liberty/tmp/ccQqyMJ7.o(.text+0x39): undefined reference to
`roundf'
collect2: ld returned 1 exit status


I realize that defining _GNU_SOURCE in linux _should_ also define
_ISOC99_SOURCE, but i included it just to be sure.

Or is this just my distro's problem with the version of gcc they've
chosen to use ?
Does anybody have an alternative solution?