develooper Front page | perl.perl5.porters | Postings from February 2001

Re: IV preservation (was Re: [PATCH 5.7.0] compiling on OS/2)

Thread Previous | Thread Next
From:
nick
Date:
February 17, 2001 09:18
Subject:
Re: IV preservation (was Re: [PATCH 5.7.0] compiling on OS/2)
Message ID:
E14UAwC-0003aA-00@roam1
Ilya Zakharevich <ilya@math.ohio-state.edu> writes:
>On Fri, Feb 16, 2001 at 10:29:33PM +0000, nick@ing-simmons.net wrote:
>> >> >Etc etc etc.  Checking that a float is an integer is
>> >> >a non-trivial and a very expensive operation.
>> >> 
>> >> No it isn't (at least for IEEE). It is a simple matter of comparing 
>> >> the (binary) exponent with the (known, constant) number of bits in the mantissa.
>> >> and then seeing if there are any non-zero bits to the right of the radix point.
>> >> (am I missing something here?).
>> >
>> >AFAIK, there is no API to extract the exponent and the mantissa from
>> >a double.  Did I miss it?
>
>> DESCRIPTION
>>        The frexp() function is used to split the number x into  a
>>        normalized  fraction  and  an  exponent which is stored in
>>        exp.              
>
>I would not think that this has anything to do with the bitpattern
>manipulations you described above.

Sure it is.
frexp() says extract the exponent and stuff it in the integer provided,
then set the exponent to 0 and return the resulting double which is 
now the fraction.

>
>> DESCRIPTION
>>        The modf() function breaks the argument x into an integral
>>        part  and  a  fractional  part, each of which has the same
>>        sign as x.  The integral part is stored in iptr.
>
>This is closer, but should not be very cheep.

You and going to make me power up that SPARC10 and go look for code ...

>> Both are "easy" to do by bit twiddling for IEEE format.
>
>AFAIU, there is no IEEE format.  IEEE mandates *which numbers* should
>be representable by IEEE floats, but now how this info is stored in
>the bitpatterns.  

Strictly speaking true. But as "minimum" float and double ranges
fit in exactly 32 and 64 bits respectively, with the 
sign, exponent, (hidden MSB), mantissa as per IEEE then in practice the 
only difference is big/little endian style ordering of the fields.

So it is almost always

struct
{
 int sign : 1;
 int exponent : X;
 int ms_mantissa : 
 int ls_mantissa;
}

The problem machines are IBMs and VAXs which pre-date 80387/IEEE which became
de-facto standard.  

>Given a processor info (and knowing that the
>compiler uses the "100% hardware" floats), one can easily write the
>bitpattern manipulation code, but I do not think this is what we
>*want* Perl to do.

I would expect modf() to be resonably fast.

>
>Ilya
-- 
Nick Ing-Simmons


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About