Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > floor(-0.5)

Reply
Thread Tools

floor(-0.5)

 
 
Francois Grieu
Guest
Posts: n/a
 
      02-06-2004
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
 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      02-07-2004
Francois Grieu <(E-Mail Removed)> 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.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
 
Reply With Quote
 
 
 
 
Francois Grieu
Guest
Posts: n/a
 
      02-07-2004
In article <(E-Mail Removed)>, Keith Thompson <(E-Mail Removed)>
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments