Velocity Reviews > floor(positive double) vs trunc(positive double) different

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

Hicham Mouline
Guest
Posts: n/a

 04-23-2010
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,

Barry Schwarz
Guest
Posts: n/a

 04-23-2010
On Fri, 23 Apr 2010 11:50:19 +0100, "Hicham Mouline"
<(E-Mail Removed)> 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

Keith Thompson
Guest
Posts: n/a

 04-23-2010
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.velocityreviews.com/forums/(E-Mail Removed) <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"