[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: trunc
From: |
Ben Pfaff |
Subject: |
Re: trunc |
Date: |
Sat, 25 Nov 2006 18:58:41 -0800 |
User-agent: |
Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) |
John Darrington <address@hidden> writes:
> On Sat, Nov 25, 2006 at 05:40:08PM -0500, Jason Stover wrote:
> BSD's math.h has no 'trunc', but both GNU and BSD have
> 'floor' in math.h, so to fix this error on BSD:
>
> src/language/stats/chisquare.c:78: undefined reference to `trunc'
>
> could we use floor instead?
>
> trunc and floor do different things if the argument is negative.
>
> According to the user documentation, "Non-integer values are
> truncated before classification". I interpret this to mean "towards
> zero".
> I suppose the most portable way is to cast to int and back again, but
> it's not very nice.
I'd suggest checking for trunc with Autoconf, then providing an
implementation based on floor if it doesn't exist, i.e. something
like this:
#ifndef HAVE_TRUNC
double
trunc (double d)
{
return d >= 0.0 ? floor (d) : -floor (-d);
}
#endif
I do something like this for the "round" function.
--
"Mon peu de succès près des femmes est toujours venu de les trop aimer."
--Jean-Jacques Rousseau
- trunc, Jason Stover, 2006/11/25