[Bug middle-end/34678] Optimization generates incorrect code with -frounding-math option (#pragma STDC FENV_ACCESS not implemented)
tkoenig at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Jan 6 19:29:16 GMT 2023
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=34678
--- Comment #46 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
Fortran gets this right:
$ cat set_rounding_mode.f90
module x
implicit none
integer, parameter :: wp = selected_real_kind(15)
contains
subroutine foo(a,b,c)
use ieee_arithmetic
real(kind=wp), dimension(4), intent(out) :: a
real(kind=wp), intent(in) :: b, c
type (ieee_round_type), dimension(4), parameter :: mode = &
[ieee_nearest, ieee_to_zero, ieee_up, ieee_down]
integer :: i
do i=1,4
call ieee_set_rounding_mode (mode(i))
a(i) = b + c
end do
end subroutine foo
end module x
program main
use x
real(kind=wp), dimension(4) :: a
call foo(a, 0.1_wp, 0.2_wp)
print *,a
end program main
$ gfortran -O3 set_rounding_mode.f90
$ ./a.out
0.30000000000000004 0.29999999999999999 0.30000000000000004
0.29999999999999999
More information about the Gcc-bugs
mailing list