This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Bug fortran/38823] New: Diagnose and treat (-2.0)**2.0 properly


On Jan 13, 2009, at 3:08 AM, "burnus at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org > wrote:

Found at:
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/0f1d7da66fa015c2

print *, (-2.0)**2.0
end
is invalid. gfortran should print a diagnostic for -std=f95/f2003/ f2008 as NAG
f95 does:
Error: Negative floating-point value raised to a real power


Fortran 2003 in the second sentence of the second paragraph of "7.1.8
Evaluation of Operations":

 "Raising a negative-valued primary of type real to a real power is
  prohibitted."

The question is whether one needs to reject it completely or only with
-std=f95. Steve (see thread) thinks the constant folding gets it wrong
(-> gives "4.0").

Current results:
- Runtime and compile time evaluation (ifort, gfortran, g95):
 -2.0**2.0 = 4.0
 -2.0**1.9 = NaN
- Mathematica:
 -2^2 = 4, -2.0^2.0 = -4.0
 2.0^1.9 = -3.73213

-2.0^1.9 will be a complex number. Maybe we can define it as taking the real part. I don't know if that is better than generating a nan here.


Thanks,
Andrew Pinski





-- Summary: Diagnose and treat (-2.0)**2.0 properly Product: gcc Version: 4.4.0 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: burnus at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38823




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]