real_info.subnormal off-by-one?
Tobias Schlüter
tobias.schlueter@physik.uni-muenchen.de
Mon May 9 15:52:00 GMT 2005
Steve,
you defined the subnormal field in the real infos as:
/* subnormal (x) = b**(emin - digit + 1) */
mpfr_set_ui (b, real_info->radix, GFC_RND_MODE);
mpfr_pow_si (b, b, real_info->min_exponent - real_info->digits + 1,
GFC_RND_MODE);
mpfr_init (real_info->subnormal);
mpfr_set (real_info->subnormal, b, GFC_RND_MODE);
The '+1' looks wrong, with a modified gfortran which sets nearest(0.,1.) to
this value, I get:
[tobi@marktplatz tests]$ cat subnorm.f90
DOUBLE PRECISION u, v
x = nearest(0.,1.)
y = 0.
print *, x, nearest(y,1.)
u = nearest(0._8,1._8)
v = 0._8
print *, u, nearest(v,1._8)
end
[tobi@marktplatz tests]$ ./a.out
2.8025969E-45 1.4012985E-45
9.881312916824931E-324 4.940656458412465E-324
[tobi@marktplatz tests]$
i.e. in both cases subnormal is by a factor 2 larger than the smallest
representable number. Note that tiny is b**(emin-1), I also think that the
number model in the standard is normalized to 0.1.... whereas IEEE floats are
normalized to 1....., which would explain the difference.
Do you agree that this is wrong or did I misunderstand the meaning of the
subnormal field?
Thanks,
- Tobi
More information about the Fortran
mailing list