Bug 27021 - Problem with nearest(tiny(o),-1.0)/2.0
Summary: Problem with nearest(tiny(o),-1.0)/2.0
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: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-04 09:56 UTC by Dominique d'Humieres
Modified: 2006-09-27 20:37 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-04-05 20:50:12


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dominique d'Humieres 2006-04-04 09:56:45 UTC
The following program

program chop
  real o, t, td, tu, x, y
  o = 1.
  t = tiny(o)
  td = nearest(t,-1.0)
  x = td/2.0
  y = nearest(tiny(o),-1.0)/2.0
  print *, x, y, x - y
end program chop

gives

  5.8774718E-39  5.8774704E-39  1.4012985E-45

on OSX 10.3.9 and GNU Fortran 95 (GCC) 4.2.0 20060401 (experimental).
I.e, nearest(tiny(o),-1.0)/2.0 does not give the same result as

  td = nearest(t,-1.0)
  x = td/2.0

Dominique
Comment 1 Carsten Lemmen 2006-04-04 10:05:45 UTC
on x86-linux gfortran 5.8774718E-39  5.8774704E-39  1.4012985E-45
             f90      5.8774718E-39  5.8774718E-39  0.0000000E+00
             pgf90    5.8774718E-39  5.8774718E-39  0.0000000
Comment 2 kargls 2006-04-05 20:50:12 UTC
I sent a preliminary patch for this problem to fortran@

http://gcc.gnu.org/ml/fortran/2006-04/msg00084.html
Comment 3 kargls 2006-09-27 20:15:36 UTC
Subject: Bug 27021

Author: kargl
Date: Wed Sep 27 20:15:22 2006
New Revision: 117257

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117257
Log:
	* configure.in: Check for GMP 4.1 or newer.  Check for MPFR 2.2.0 
	or newer.
	* configure: Regenerated.
	* doc/install.texi: Document required versions of GMP and MPFR.
	* fortran/arith.c: Conditionally include arctangent2().
	(gfc_check_real_range): Use mpfr_subnormalize in preference to local
	hack.
	* fortran/trans-intrinsic.c (gfc_get_intrinsic_lib_fndecl): Append
	l for long double functions.
	* fortran/simplify.c: Wrap Copyright to new line.
	(gfc_simplify_atan2): Use mpfr_atan2 in preference to arctangent2().
        (gfc_simplify_log): Ditto.


	PR fortran/28276
	* fortran/simplify.c (gfc_simplify_exponent): Use mpfr_get_exp in
	preference to broken local hack.

	PR fortran/27021
	* fortran/simplify.c (gfc_simplify_nearest): Use mpfr_nexttoward and
	mpfr_subnormalize to handle numbers near zero in preference to broken
	 local hack.

	PR fortran/28276
	* testsuite/gfortran.dg/exponent_1.f90: New test.

	PR fortran/27021
	* testsuite/gfortran.dg/nearest_1.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/exponent_1.f90
    trunk/gcc/testsuite/gfortran.dg/nearest_1.f90
Modified:
    trunk/ChangeLog
    trunk/configure
    trunk/configure.in
    trunk/gcc/ChangeLog
    trunk/gcc/doc/install.texi
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/arith.c
    trunk/gcc/fortran/simplify.c
    trunk/gcc/fortran/trans-intrinsic.c
    trunk/gcc/testsuite/ChangeLog

Comment 4 kargls 2006-09-27 20:37:37 UTC
Fixed on trunk.  Won't be fixed on 4.1.