FW: Why does math.h not declare function round?

이종민 <[email protected]>
Newsgroups org.kernel.vger.linux-c-programming
Message-ID <FE65CEDE566B4EA39A9BBA400D8FE30A@OrangeMini>
 

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Steve Graegert
Sent: Monday, September 24, 2007 4:10 PM
To: Plato
Cc: linux-c-programming
Subject: Re: Why does math.h not declare function round?

On 9/24/07, Plato <[email protected]> wrote:
> Hi!
>     I made such a program foo.c:
>
> #include <math.h>
>
> int main()
> {
>     double bar=1.2;
>     printf("%f\n", round(bar));
> }
>
> Then compile and run:
> [root@so41 tmp]# gcc foo.c -ofoo -lm
> [root@so41 tmp]# ./foo
> 0.000000
>
> The result was obviously wrong. Then I add statement:
> #include <math.h>
> double round(double x);
>
> int main()
> {
>     double bar=1.2;
>     printf("%f\n", round(bar));
> }
>
> Then compile and run:
> [root@so41 tmp]# gcc foo.c -ofoo -lm
> [root@so41 tmp]# ./foo
> 1.000000
>
> Now it's right.
>
> I wonder why function round not declared in math.h. Anyone have idea?

It is available in C99 mode only (see <bits/mathcalls.h>):

#ifdef __USE_ISOC99
__MATHCALLX (round,, (_Mdouble_ __x), (__const__));

To write fully portable code use floor() and ceil() instead.

	\Steve

--

Steve Grägert <[email protected]>
Internet: http://digitalether.de
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected] More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.