floor(-0.5)

Discussion in 'C Programming' started by Francois Grieu, Feb 6, 2004.

  1. In ISO/IEC 9899:1999, it is unambiguous that floor(-0.5)
    has the value -1 (converted to double).

    Was this the case in earlier C standards?

    Is anyone aware of an implementaton that has it wrong ?

    Fran├žosi Grieu
    Francois Grieu, Feb 6, 2004
    #1
    1. Advertising

  2. Francois Grieu <> writes:
    > In ISO/IEC 9899:1999, it is unambiguous that floor(-0.5)
    > has the value -1 (converted to double).
    >
    > Was this the case in earlier C standards?


    C90 says:

    The floor function returns the largest integral value not greater
    than x, expressed as a double.

    C99 says:

    The floor functions return |_ x _|, expressed as a floating-point number.

    where "|_" and "_|" are my crude rendition of the mathematical symbol
    for the floor function.

    > Is anyone aware of an implementaton that has it wrong ?


    I'm not -- and given that the function is called "floor", getting it
    wrong (say, by rounding towards 0.0) would be a pretty dumb mistake.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
    Schroedinger does Shakespeare: "To be *and* not to be"
    Keith Thompson, Feb 7, 2004
    #2
    1. Advertising

  3. In article <>, Keith Thompson <>
    wrote:

    > C90 says:
    >
    > The floor function returns the largest integral value not greater
    > than x, expressed as a double.


    Very clear indeed.


    > C99 says:
    >
    > The floor functions return |_ x _|, expressed as a floating-point number.
    >
    > where "|_" and "_|" are .. the mathematical symbol for the floor function.


    And |_ x _| is defined in ?3.19 as
    ... "the greatest integer less than or equal to x.
    Example: |_ 2.4 _| is 2, |_ -2.4 _| is -3."


    Thanks for the C90 quote !

    Francois Grieu
    Francois Grieu, Feb 7, 2004
    #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. SpaceCowboy
    Replies:
    6
    Views:
    1,073
    Josef Garvi
    Aug 15, 2003
  2. John
    Replies:
    3
    Views:
    338
    Chris Smith
    Feb 11, 2005
  3. John
    Replies:
    9
    Views:
    369
    Kanenas
    Apr 13, 2005
  4. Francois Grieu

    floor(-0.5)

    Francois Grieu, Feb 6, 2004, in forum: C Programming
    Replies:
    0
    Views:
    408
    Francois Grieu
    Feb 6, 2004
  5. Christoph Zwerschke

    Command line option -Q (floor division)

    Christoph Zwerschke, Mar 23, 2006, in forum: Python
    Replies:
    2
    Views:
    283
    Georg Brandl
    Mar 29, 2006
Loading...

Share This Page