This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [PATCH,Fortran] Handle 'q' exponent-letter in real-literal-constant
- From: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- To: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Mon, 25 Apr 2011 11:43:20 -0700
- Subject: Re: [PATCH,Fortran] Handle 'q' exponent-letter in real-literal-constant
- References: <20110425184207.GA7936@troutmask.apl.washington.edu>
On Mon, Apr 25, 2011 at 11:42:07AM -0700, Steve Kargl wrote:
>
> 2011-04-25 Steven G. Kargl <kargl@gcc.gnu.org.>
>
> PR fortran/48720
> * gfortran.texi: Document the 'Q' exponent-letter extension.
> * primary.c (match_real_constant): Accept 'Q' as exponent-letter
> for REAL(16) real-literal-constant with a fallback to REAL(10) or
> error if REAL(10) is not available.
Of course, it would be helpful to include the patch.
--
Steve
Index: gfortran.texi
===================================================================
--- gfortran.texi (revision 172773)
+++ gfortran.texi (working copy)
@@ -1237,6 +1237,7 @@ without warning.
* Missing period in FORMAT specifications::
* I/O item lists::
* BOZ literal constants::
+* @code{Q} exponent-letter::
* Real array indices::
* Unary operators::
* Implicitly convert LOGICAL and INTEGER values::
@@ -1427,6 +1428,23 @@ To support legacy codes, GNU Fortran all
of the @code{READ} statement, and the output item lists of the
@code{WRITE} and @code{PRINT} statements, to start with a comma.
+@node @code{Q} exponent-letter
+@subsection @code{Q} exponent-letter
+@cindex @code{Q} exponent-letter
+
+GNU Fortran accepts real literal constants with an exponent-letter
+of @code{Q}, for example, @code{1.23Q45}. Prior to version 4.6.1,
+GNU Fortran silently accepted @code{Q} as an alias for the single
+precision exponent-letter @code{E}. With the introduction of software
+support for @code{REAL(16)} (i.e., quadruple precision) on i386 and
+x86_64 targets, the interpretation of @code{Q} has been updated to
+mean a @code{REAL(16)} real-literal-constant. This aligns GNU Fortran
+with many commercially available compilers. If the target does not
+support @code{REAL(16)} but has a @code{REAL(10)} type, then the
+real-literal-constant will be interpreted as a @code{REAL(10)} entity.
+In the absence of @code{REAL(16)} and @code{REAL(10)}, an error will
+occur.
+
@node BOZ literal constants
@subsection BOZ literal constants
@cindex BOZ literal constants
Index: primary.c
===================================================================
--- primary.c (revision 172773)
+++ primary.c (working copy)
@@ -541,6 +541,17 @@ match_real_constant (gfc_expr **result,
goto done;
exp_char = c;
+
+ if (c == 'q')
+ {
+ if (gfc_notify_std (GFC_STD_GNU, "Extension: exponent-letter 'q' in "
+ "real-literal-constant at %C") == FAILURE)
+ return MATCH_ERROR;
+ else
+ gfc_warning("Extension: exponent-letter 'q' in real-literal-constant "
+ "at %C");
+ }
+
/* Scan exponent. */
c = gfc_next_ascii_char ();
count++;
@@ -616,6 +627,29 @@ done:
kind = gfc_default_double_kind;
break;
+ case 'q':
+ if (kind != -2)
+ {
+ gfc_error ("Real number at %C has a 'q' exponent and an explicit "
+ "kind");
+ goto cleanup;
+ }
+
+ /* The maximum possible real kind type parameter is 16. First, try
+ that for the kind, then fallback to trying kind=10 (Intel 80 bit)
+ extended precision. If neither value works, just given up. */
+ kind = 16;
+ if (gfc_validate_kind (BT_REAL, kind, true) < 0)
+ {
+ kind = 10;
+ if (gfc_validate_kind (BT_REAL, kind, true) < 0)
+ {
+ gfc_error ("Invalid real kind %d at %C", kind);
+ goto cleanup;
+ }
+ }
+ break;
+
default:
if (kind == -2)
kind = gfc_default_real_kind;