From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1665) id 8A9A93858D37; Wed, 21 Sep 2022 09:15:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8A9A93858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663751734; bh=FD4fz07DHXyigKw+MNkvrxf6d94i5kD5s3IJewB8NDc=; h=From:To:Subject:Date:From; b=l90AXSkjOrEU8etVRJxNIQ8swQjZPGH2CXBp1af1ia+JY5h/YjrzOEFw01ORnVl4W A6HSl14ThfRZFyW3AsZJXPxpvOQmeHnj1BrcIoaNTwzcV93jBUUCB3hZwcyd/waSEO lDTDtKNANG5bX+hXtYeLBfqg3HRQt3UVu7MmkviE= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: =?utf-8?q?Fran=E0=A4=A5=E0=A4=88ois-Xavier_Coudert?= To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-2758] Fortran: handle RADIX kind in IEEE_SET_ROUNDING_MODE X-Act-Checkin: gcc X-Git-Author: Francois-Xavier Coudert X-Git-Refname: refs/heads/master X-Git-Oldrev: dd9e5f4db2debf1429feab7f785962ccef6e0dbd X-Git-Newrev: 519196a27cf534e94f158733b25a4f9d10737031 Message-Id: <20220921091534.8A9A93858D37@sourceware.org> Date: Wed, 21 Sep 2022 09:15:34 +0000 (GMT) List-Id: https://gcc.gnu.org/g:519196a27cf534e94f158733b25a4f9d10737031 commit r13-2758-g519196a27cf534e94f158733b25a4f9d10737031 Author: Francois-Xavier Coudert Date: Wed Sep 21 11:06:19 2022 +0200 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 libgfortran/ * ieee/ieee_arithmetic.F90 (IEEE_SET_ROUNDING_MODE): Handle RADIX argument better. gcc/testsuite/ * gfortran.dg/ieee/rounding_3.f90: New test. Diff: --- gcc/testsuite/gfortran.dg/ieee/rounding_3.f90 | 27 +++++++++++++++++++++++++++ libgfortran/ieee/ieee_arithmetic.F90 | 12 +++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) 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