chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-hackers] Fix solaris9 build for missing trunc, round, isinf


From: Florian Zumbiehl
Subject: Re: [Chicken-hackers] Fix solaris9 build for missing trunc, round, isinf math functions
Date: Sat, 20 Apr 2013 19:10:00 +0200
User-agent: Mutt/1.5.20 (2009-06-14)

Hi,

> I've spotted an error in the patch.
> 
> static inline double trunc(double x) { return (x > 0 ? floor(x) :
> floor(x) + 1); }
> 
> should be:
> 
> static inline double trunc(double x) { return (x >= 0 ? floor(x) :
> floor(x) + 1); }

| $ cat foo.c
| 
| #include <stdio.h>
| #include <math.h>
| 
| double trunc_x(double x) { return (x >= 0 ? floor(x) : floor(x) + 1); }
| double round_x(double x) { return (x - floor(x) >= 0.5 ? floor(x) + 1 : 
floor(x)); }
| 
| int main(){
|         printf("%f %f\n",trunc(-42),trunc_x(-42));
|         printf("%f %f\n",round(-42.5),round_x(-42.5));
| }
| 
| $ gcc -lm -o foo foo.c && ./foo
| -42.000000 -41.000000
| -43.000000 -42.000000

AFAICT, there are a few more bugs in there, in particular in the handling
of infinities and NaN, and I think even the number handling is incorrect in
more corner cases, but I currently don't have the time to think about that
in detail.

Florian



reply via email to

[Prev in Thread] Current Thread [Next in Thread]