[LCP]Rounding questions
Steve Baker
ice at mama.indstate.edu
Fri Sep 6 06:26:06 UTC 2002
Chuck Martin <nrocinu at myrealbox.com> wrote:
> On Thu, Sep 05, 2002 at 12:36:39PM -0500, Steve Baker wrote:
> > It seems perplexing, but the problem is that round is not prototyped in
> > math.h, or anywhere for that matter. This is clearly a glibc maintainer
> > issue. Add to your program at the top:
> >
> > double round(double);
>
> Thank you! This works. Do you happen to know why rint() works without
> doing this? I can't seem to find a prototype for it anywhere, including
> math.h.
Augh... I _always_ forget about features.h. round() is defined after all,
but only if you have _ISOC99_SOURCE defined at the very very top of your C
file before any #includes (or _GNU_SOURCE, which turns on other things as
well). If you look in /usr/include/features.h you'll find all the "features"
you can select from.
rint() is a BSD'ism thus it is enabled by default. round() is a C99 feature
thus you must enable its use.
I was using cpp to see if round was being defined, but didn't see it thus I
assumed it wasn't defined anywhere, but was in fact, only #defined out of
existence. I overlooked it while rgrep'ing for it because all math.h function
calls are prototyped like:
__MATHCALL (round,, (_Mdouble_ __x));
They don't make it easy to track down, but there you go. Stick:
#define _ISOC99_SOURCE
At the very top of your C file and you're C99 ready.
> Now this brings me to the other question I asked when I started this
> thread. How portable is this? The man page says it conforms to C99,
> but I'm not up on all of the standards and where they're all used.
> Will using this instead of my own rounding routine cause problems in
> portability, and if so, to what extent?
Any system that conforms to C99 should be OK, and most should, so I imagine
it's portable. You may have to jump through a hoop or two like this to get it
to work though.
- Steve
More information about the linuxCprogramming
mailing list