floor(positive double) vs trunc(positive double) different

Discussion in 'C Programming' started by Hicham Mouline, Apr 23, 2010.

  1. If we consider a positive double argument, that is not 0, not NaN not
    infinity.

    do floor() and trunc() return the same value then?

    Regards,
     
    Hicham Mouline, Apr 23, 2010
    #1
    1. Advertising

  2. On Fri, 23 Apr 2010 11:50:19 +0100, "Hicham Mouline"
    <> wrote:

    >If we consider a positive double argument, that is not 0, not NaN not
    >infinity.
    >
    >do floor() and trunc() return the same value then?


    floor() rounds down. trunc() rounds to 0. For positive values, and
    0, the results are the same.

    --
    Remove del for email
     
    Barry Schwarz, Apr 23, 2010
    #2
    1. Advertising

  3. none <""gil\"@(none)"> writes:
    > Ersek, Laszlo wrote:
    >>
    >> <snip part that made me laugh>
    >>
    >> I think they have to return the exact same value under said circumstances.
    >>
    >> C99 7.12.9.2 The floor functions p2
    >>
    >> "The floor functions compute the largest integer value not greater than x."
    >>
    >> C99 7.12.9.8 The trunc functions p2
    >>
    >> "The trunc functions round their argument to the integer value,
    > > **in floating format** [emphasis added], nearest to but no larger
    > > in magnitude than the argument."

    >
    > Do both return a float like trunc(), or does floor() return an integer?


    Both return double (not float).

    Hint: The best way to answer simple questions like that
    is to read the documentation. If you don't have something
    like "man floor" and/or "man trunc" on your system, you can
    always grab a copy of the latest draft of the C standard from
    <http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf>.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Apr 23, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. arti

    trunc in verilog

    arti, May 10, 2006, in forum: VHDL
    Replies:
    0
    Views:
    586
  2. Sydex
    Replies:
    12
    Views:
    6,568
    Victor Bazarov
    Feb 17, 2005
  3. Giulio

    undefined reference to `trunc'

    Giulio, Nov 24, 2004, in forum: C Programming
    Replies:
    7
    Views:
    3,299
    Dave Vandervies
    Nov 26, 2004
  4. =?Utf-8?B?RGF2ZQ==?=
    Replies:
    2
    Views:
    16,077
    Alexey Smirnov
    Jul 15, 2007
  5. aryan

    ios::trunc vs unlink

    aryan, Jun 16, 2008, in forum: C++
    Replies:
    3
    Views:
    775
    James Kanze
    Jun 17, 2008
Loading...

Share This Page