On Wed, Jan 05, 2000 at 09:23:57AM +0100, Martin Cracauer wrote:
> > 
> > #define JSDOUBLE_IS_INT(d, i) (JSDOUBLE_IS_FINITE(d) && \
> >     !JSDOUBLE_IS_NEGZERO(d) && ((d) == (i = (jsint)(d))))
> 
> Ah, OK, this macro is a conversion where the undefined result of the
> (int)double_bigger_max_int is (intentionally) used as a speed hack of
> a range check.

Unfortunately I think it's used as more than just a range check. It also
checks if the floating point part of the value is 0, as in a "true"
integer, not just if the integer part is in range of the int type.

> static inline int cra_is_int(const double d, int *const i)
> {
>   if (d <= (double)INT_MAX && d >= (double)INT_MIN) {
>     *i = (int)d;
>     return 1;
>   } else
>     return 0;
> }

If this is used then for example the double 3.14159 would return true,
when the intention was that it should return false, because the double
has a floating point part, and hence cannot be stored as an integer
without data loss.

Martin, your solution looked great, but if my observations are correct
I'm afraid we are back to square one with fpsetmask(). :(

Of course, an option would be to add a check for the floating point part
in Martin's suggested c function, but that would add a lot of overhead
which the responsible people for this code won't accept since
JSDOUBLE_IS_INT is a frequently used macro. If anyone got a suggestion
for a clean way to do this check.. Speak up :).

Markus

-- 

Markus Holmberg         |       Give me UNIX or give me a typewriter.
[EMAIL PROTECTED]        |       http://www.freebsd.org/


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to