[LCP]Rounding questions

Andrew Weaver Andrew.Weaver at tecnomen.fi
Thu Sep 5 18:51:05 UTC 2002


Hmmm.... I couldn't find any reference to "round" on a GNU/Linux box. It's
not in "math.h". What system are you using?

On Thursday, September 05, 2002 9:52 AM, Chuck Martin
[SMTP:nrocinu at myrealbox.com] wrote:
> I'm having problems getting the round() function to work.  For some
> reason, it always returns 0.  If I put the following line in a program,
> it outputs "0" followed by a newline:
> 
> 	printf("%f\n", round(390));
> 
> If I change "round" to "rint", it outputs 390, as it should.  Changing
> "390" to "390.0" or "(double) 390" makes no difference, as I would expect.
> I'm doing this in an existing program that already includes math.h, but
> I've also had the problem that if I try to test this with a standalone
> program, like this:
> 
> 	#include <stdio.h>
> 	#include <math.h>
> 
> 	int main()
> 	{
> 		printf("%f\n", round(390));
> 	}
> 
> it won't compile.  Instead, I get an error message that says "undefined
> reference to `round'".  Why is it doing this?
> 
> Another concern I have is how portable round() is.  I realize this is a
> Linux C programming list, but I'd like this to be portable.  The man page
> for round(3) says that it conforms to C99, but I'm not sure how portable
> that is, especially on older systems.  This program originally had it's
> own rounding code, but I found a strange bug in it that I've been unable
> to figure out.  If I have to resort to going back to the old code, I may
> have to present that bug here to see if anyone else can figure it out,
> but using round() would seem to be a simpler solution if I can make it
> work and it's portable.
> 
> Thanks in advance.
> 
> Chuck
> 
> 
> _______________________________________________
> This is the Linux C Programming List
> :  http://lists.linux.org.au/listinfo/linuxcprogramming List




More information about the linuxCprogramming mailing list