linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: 이종민 <anapple.orange@gmail.com>
To: linux-c-programming@vger.kernel.org
Subject: FW: Why does math.h not declare function round?
Date: Wed, 14 May 2008 23:31:47 +0900	[thread overview]
Message-ID: <FE65CEDE566B4EA39A9BBA400D8FE30A@OrangeMini> (raw)

 

-----Original Message-----
From: linux-c-programming-owner@vger.kernel.org [mailto:linux-c-programming-owner@vger.kernel.org] 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 <zhangguoqiang@xunlei.com> 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 <steve@graegert.com>
Internet: http://digitalether.de
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to majordomo@vger.kernel.org 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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

             reply	other threads:[~2008-05-14 14:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-14 14:31 이종민 [this message]
  -- strict thread matches above, loose matches on Subject: below --
2008-05-14 14:31 FW: Why does math.h not declare function round? 이종민

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=FE65CEDE566B4EA39A9BBA400D8FE30A@OrangeMini \
    --to=anapple.orange@gmail.com \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).