Bug 29312 - Errors in subnormal calculation
Summary: Errors in subnormal calculation
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: 4.2.0
Assignee: kargl
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2006-10-01 23:00 UTC by Dominique d'Humieres
Modified: 2006-10-09 20:58 UTC (History)
1 user (show)

See Also:
Host: PPC OSX 10.3.9
Target: powerpc-apple-darwin7
Build: gcc version 4.2.0 20060930
Known to work:
Known to fail:
Last reconfirmed: 2006-10-01 23:52:53


Attachments
test of NEAREST, SPACING, and RRSPACING (676 bytes, text/plain)
2006-10-01 23:05 UTC, Dominique d'Humieres
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dominique d'Humieres 2006-10-01 23:00:03 UTC
Copy of http://gcc.gnu.org/ml/fortran/2006-10/msg00009.html

With gcc version 4.2.0 20060930 (experimental), gmp 4.2.1, and mpfr 2.2.0,
on OSX 10.3.9/G5, the following code

real x
x = -0.375*tiny(x)
end

fails with:

init2.c:51:  assertion failed: p >= 2 && p <= ((mpfr_prec_t)((mpfr_prec_t)(~(mpfr_prec_t)0)>>1))
test_spacing_red.f90:0: internal compiler error: Abort trap
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

Copy of http://gcc.gnu.org/ml/fortran/2006-10/msg00013.html

The following code

real x, xd, xu
x = -3.0*epsilon(x)
xd = abs(fraction(x))*set_exponent(real(radix(x), kind=kind(x)), 1+digits(x))
print *, -3.0*epsilon(1.0)-x
print *, x, spacing(x), spacing(-3.0*epsilon(1.0))
print *, x, xd, rrspacing(x), rrspacing(-3.0*epsilon(1.0))
end

gives

   0.000000    
 -3.5762787E-07  2.8421709E-14  5.6843419E-14
 -3.5762787E-07  1.2582912E+07  1.2582912E+07   6291456.    

where the last column of the two last lines computed from
spacing(-3.0*epsilon(1.0)) and rrspacing(-3.0*epsilon(1.0))
(hence the 'compile time' in the subject) do not match the
values computed through a variable.

Copy of http://gcc.gnu.org/ml/fortran/2006-10/msg00014.html

The following code

real x
x = -3.0*(nearest(tiny(x),1.0)-tiny(x))
print *, x
end

gives

   0.000000    

instead of something like (xlf)

 -0.4203895393E-44
Comment 1 Dominique d'Humieres 2006-10-01 23:05:45 UTC
Created attachment 12367 [details]
test of NEAREST, SPACING, and RRSPACING

The reported errors come from the attached code.
Comment 2 kargl 2006-10-01 23:52:53 UTC
I believe the bugs with the various intrinsics are all related.
The problem stems from some confusion over the meaning of 
emin and emax in gfortran, the IEEE 754 standard, and mpfr.
Comment 3 kargl 2006-10-09 20:55:40 UTC
Subject: Bug 29312

Author: kargl
Date: Mon Oct  9 20:55:29 2006
New Revision: 117584

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117584
Log:
2006-10-06  Steven G. Kargl  <kargl@gcc.gnu.org>
 
	* gfortran.h: Define GFC_MPFR_TOO_OLD via mpfr version info.
	* arith.c (arctangent, gfc_check_real_range): Use it.	
	* simplify.c (gfc_simplify_atan2, gfc_simplify_exponent,
	gfc_simplify_log, gfc_simplify_nearest): Use it.

	PR fortran/15441
	PR fortran/29312
	* iresolve.c (gfc_resolve_rrspacing): Give rrspacing library
	routine hidden precision argument.
	(gfc_resolve_spacing): Give spacing library routine hidden
	precision, emin - 1, and tiny(x) arguments.
	* simplify.c (gfc_simplify_nearest): Remove explicit subnormalization.
	(gfc_simplify_rrspacing): Implement formula from Fortran 95 standard.
	(gfc_simplify_spacing): Implement formula from Fortran 2003 standard.
	* trans-intrinsic.c (gfc_intrinsic_map_t) Declare rrspacing and
	spacing via LIBF_FUNCTION
	(prepare_arg_info, call_builtin_clz, gfc_conv_intrinsic_spacing,
	gfc_conv_intrinsic_rrspacing): Remove functions.
	(gfc_conv_intrinsic_function): Remove calls to
	gfc_conv_intrinsic_spacing and gfc_conv_intrinsic_rrspacing.
	* f95-lang.c (gfc_init_builtin_functions): Remove __builtin_clz,
	__builtin_clzl and __builtin_clzll


2006-10-06  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/15441
	PR fortran/29312
	* configure.ac: Add HAVE_LDEXPF, HAVE_LDEXP, and HAVE_LDEXPL
	* m4/spacing.m4: New file.  Use new HAVE_* defines.
	* m4/rrspacing.m4: Ditto.
	* Makefile.am: Handle new files.
	* configure: Regenerated.
	* Makefile.in: Ditto.
	* config.h.in: Ditto.
	* generated/spacing_r4.c: Generated.
	* generated/spacing_r8.c: Ditto.
	* generated/spacing_r10.c: Ditto.
	* generated/spacing_r16.c: Ditto.
	* generated/rrspacing_r4.c: Ditto.
	* generated/rrspacing_r8.c: Ditto.
	* generated/rrspacing_r10.c: Ditto.
	* generated/rrspacing_r16.c: Ditto.


Added:
    trunk/libgfortran/generated/rrspacing_r10.c
    trunk/libgfortran/generated/rrspacing_r16.c
    trunk/libgfortran/generated/rrspacing_r4.c
    trunk/libgfortran/generated/rrspacing_r8.c
    trunk/libgfortran/generated/spacing_r10.c
    trunk/libgfortran/generated/spacing_r16.c
    trunk/libgfortran/generated/spacing_r4.c
    trunk/libgfortran/generated/spacing_r8.c
    trunk/libgfortran/m4/rrspacing.m4
    trunk/libgfortran/m4/spacing.m4
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/arith.c
    trunk/gcc/fortran/f95-lang.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/iresolve.c
    trunk/gcc/fortran/simplify.c
    trunk/gcc/fortran/trans-intrinsic.c
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/Makefile.am
    trunk/libgfortran/Makefile.in
    trunk/libgfortran/config.h.in
    trunk/libgfortran/configure
    trunk/libgfortran/configure.ac

Comment 4 kargl 2006-10-09 20:58:07 UTC
Fixed on trunk (until someone tells me ldexp doesn't exist)