public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: FX <fxcoudert@gmail.com>
To: Fortran <fortran@gcc.gnu.org>
Cc: Mikael Morin <morin-mikael@orange.fr>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Fortran 2018 rounding modes changes
Date: Wed, 21 Sep 2022 11:15:35 +0200	[thread overview]
Message-ID: <73BF06B8-3E5D-4D7F-9A51-7FE3120B9DC4@gmail.com> (raw)
In-Reply-To: <99C0538F-658C-4A7C-92B9-29E0C38A28CE@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 63 bytes --]

Follow-up patch, including a test, committed as attached.

FX


[-- Attachment #2: 0001-Fortran-handle-RADIX-kind-in-IEEE_SET_ROUNDING_MODE.patch --]
[-- Type: application/octet-stream, Size: 2978 bytes --]

From 1aea1cb714f5a676901e702fc733595e0c9ad413 Mon Sep 17 00:00:00 2001
From: Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
Date: Wed, 21 Sep 2022 11:06:19 +0200
Subject: [PATCH] Fortran: handle RADIX kind in IEEE_SET_ROUNDING_MODE

Make sure that calling IEEE_SET_ROUNDING_MODE with RADIX=10 does not
affect the binary rounding mode.

2022-09-21  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>

libgfortran/

	* ieee/ieee_arithmetic.F90 (IEEE_SET_ROUNDING_MODE): Handle
	RADIX argument better.

gcc/testsuite/

	* gfortran.dg/ieee/rounding_3.f90: New test.
---
 gcc/testsuite/gfortran.dg/ieee/rounding_3.f90 | 27 +++++++++++++++++++
 libgfortran/ieee/ieee_arithmetic.F90          | 12 ++++++---
 2 files changed, 36 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/ieee/rounding_3.f90

diff --git a/gcc/testsuite/gfortran.dg/ieee/rounding_3.f90 b/gcc/testsuite/gfortran.dg/ieee/rounding_3.f90
new file mode 100644
index 00000000000..ff4e834a042
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/ieee/rounding_3.f90
@@ -0,0 +1,27 @@
+! { dg-do run }
+
+  ! Test IEEE_GET_ROUNDING_MODE and IEEE_SET_ROUNDING_MODE
+  ! with a RADIX argument
+  use, intrinsic :: ieee_arithmetic
+  implicit none
+
+  real :: sx1
+  type(ieee_round_type) :: r
+
+  if (ieee_support_rounding(ieee_up, sx1) .and. &
+      ieee_support_rounding(ieee_down, sx1)) then
+
+    call ieee_set_rounding_mode(ieee_up)
+    call ieee_get_rounding_mode(r)
+    if (r /= ieee_up) stop 1
+
+    call ieee_set_rounding_mode(ieee_down, radix=2)
+    call ieee_get_rounding_mode(r, radix=2)
+    if (r /= ieee_down) stop 2
+
+    call ieee_set_rounding_mode(ieee_up, radix=10)
+    call ieee_get_rounding_mode(r, radix=2)
+    if (r /= ieee_down) stop 3
+  end if
+
+end
diff --git a/libgfortran/ieee/ieee_arithmetic.F90 b/libgfortran/ieee/ieee_arithmetic.F90
index ce30e4afca3..4c8e3bb5e64 100644
--- a/libgfortran/ieee/ieee_arithmetic.F90
+++ b/libgfortran/ieee/ieee_arithmetic.F90
@@ -816,7 +816,7 @@ REM_MACRO(4,4,4)
                      IEEE_SUPPORT_ROUNDING_NOARG
   end interface
   public :: IEEE_SUPPORT_ROUNDING
-  
+
   ! Interface to the FPU-specific function
   interface
     pure integer function support_rounding_helper(flag) &
@@ -839,7 +839,7 @@ REM_MACRO(4,4,4)
                      IEEE_SUPPORT_UNDERFLOW_CONTROL_NOARG
   end interface
   public :: IEEE_SUPPORT_UNDERFLOW_CONTROL
-  
+
   ! Interface to the FPU-specific function
   interface
     pure integer function support_underflow_control_helper(kind) &
@@ -1074,7 +1074,13 @@ contains
         integer, value :: val
       end subroutine
     end interface
-    
+
+    ! We do not support RADIX = 10, and such calls should not
+    ! modify the binary rounding mode.
+    if (present(RADIX)) then
+      if (RADIX == 10) return
+    end if
+
     call helper(ROUND_VALUE%hidden)
   end subroutine
 
-- 
2.25.1


      reply	other threads:[~2022-09-21  9:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-31 18:29 FX
2022-08-31 20:42 ` Bernhard Reutner-Fischer
2022-08-31 21:23   ` FX
2022-09-10 10:21 ` FX
2022-09-19 12:26   ` FX
2022-09-19 15:35 ` Mikael Morin
2022-09-19 16:17   ` FX
2022-09-19 17:09     ` Mikael Morin
2022-09-19 17:29       ` FX
2022-09-21  9:15         ` FX [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=73BF06B8-3E5D-4D7F-9A51-7FE3120B9DC4@gmail.com \
    --to=fxcoudert@gmail.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=morin-mikael@orange.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).