HUGE() pain in the ...

Tobias Schlüter tobias.schlueter@physik.uni-muenchen.de
Sun Jul 18 20:38:00 GMT 2004


Steve Kargl wrote:
> On Sun, Jul 18, 2004 at 02:20:01PM +0200, Tobias Schl?ter wrote:
>>How about using a base 16 string? real_from_string2 supports those as well.
>>
> 
> 
> This would necessitate a complete rewite of gfc_conv_mpfr_to_tree().

I don't think this is a bad idea :-) Conversion to decimal introduces
precision loss in any case, even though it does unfortunately manifest itself
in a more prominent place with your mpfr rewrite.

> For example, the mpfr representation of the number -1.123 will be give
> p = -112300000000000    exp=1  (base 10)
> p = 11f7ced916873       exp=1  (base 16)
> gfc_conv_mpfr_to_tree() takes p and exp to generate -.1123e1.  It is
> not at all clear to me (based on the lack of documentation in real.c)
> what the proper form of the hex string is.  In particular,
> p = 11f7ced916873 is the hex representation of the 53-bit significand.
> Do we assign p to a 64 bit integer, left shift by 11 bits, set
> the lower 11 bits to a biased exponent, and then convert the 64-bit
> into a hex representation?
> 

>From what I can see, looking at real_to_hexadecimal(), the form is
   [sign]0x0.[significand]p[exp_sign][exponent]
where the exponent is decimal. real_from_string() seem to accept arbitrary
mantissas, so the don't have to start with '0.'.

So I think that you will only have to replace '@' by 'p' as exponent
delimiter, prefix the string by 0x, and it should do the right thing.

Hope this helps,
- Tobi



More information about the Fortran mailing list