public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/109186] New: nearest(huge(x),-1.0_kind(x)) half of correct value
@ 2023-03-19  1:46 john.harper at vuw dot ac.nz
  2023-03-19  5:06 ` [Bug fortran/109186] " jvdelisle at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: john.harper at vuw dot ac.nz @ 2023-03-19  1:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109186

            Bug ID: 109186
           Summary: nearest(huge(x),-1.0_kind(x)) half of correct value
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: john.harper at vuw dot ac.nz
  Target Milestone: ---

With all four real kinds available in gfortran_12 nearest(x,y) with x = huge
and y = -1 this program gave about half the correct result. Ifort gave correct
results for the 3 different kinds it has: sp,dp,qp.

The program:

  implicit none
  integer,parameter::sp = kind(1.0), dp=kind(1d0), ncases = 2, &
       ep = selected_real_kind(18),qp = selected_real_kind(33)
  character(*),parameter:: fmt(4) = &
       "(A,ES"//["16.08E2","26.17E3","30.20E4","44.34E4"]//")"
  character(24),dimension(2):: splist,dplist,eplist,qplist 
  integer n
  real(sp),parameter::sp1 = 1.0_sp
  real(sp):: spx(ncases) = [huge(sp1),nearest(huge(sp1),-sp1)]
  data splist/'huge(sp1)','nearest(huge(sp1),-sp1)'/
  real(dp),parameter::dp1 = 1.0_dp
  real(dp):: dpx(ncases) = [huge(dp1),nearest(huge(dp1),-dp1)]
  data dplist/'huge(dp1)','nearest(huge(dp1),-dp1)'/
  real(ep),parameter::ep1 = 1.0_ep
  real(ep):: epx(ncases) = [huge(ep1),nearest(huge(ep1),-ep1)]
  data eplist/'huge(ep1)','nearest(huge(ep1),-ep1)'/
  real(qp),parameter::qp1 = 1.0_qp
  real(qp):: qpx(ncases) = [huge(qp1),nearest(huge(qp1),-qp1)]
  data qplist/'huge(qp1)','nearest(huge(qp1),-qp1)'/

  print fmt(1),(splist(n),spx(n),n=1,ncases)
  print fmt(2),(dplist(n),dpx(n),n=1,ncases)
  print fmt(3),(eplist(n),epx(n),n=1,ncases)
  print fmt(4),(qplist(n),qpx(n),n=1,ncases)
end program

The output on ubuntu (Linux 86_64)
huge(sp1)                 3.40282347E+38
nearest(huge(sp1),-sp1)   1.70141173E+38
huge(dp1)                 1.79769313486231571E+308
nearest(huge(dp1),-dp1)   8.98846567431157854E+307
huge(ep1)                 1.18973149535723176502E+4932
nearest(huge(ep1),-ep1)   5.94865747678615882511E+4931
huge(qp1)                 1.1897314953572317650857593266280070E+4932
nearest(huge(qp1),-qp1)   5.9486574767861588254287966331400351E+4931

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-03-24 18:46 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-19  1:46 [Bug fortran/109186] New: nearest(huge(x),-1.0_kind(x)) half of correct value john.harper at vuw dot ac.nz
2023-03-19  5:06 ` [Bug fortran/109186] " jvdelisle at gcc dot gnu.org
2023-03-19  8:47 ` john.harper at vuw dot ac.nz
2023-03-19 19:30 ` anlauf at gcc dot gnu.org
2023-03-19 19:58 ` anlauf at gcc dot gnu.org
2023-03-19 20:45 ` anlauf at gcc dot gnu.org
2023-03-20 17:46 ` cvs-commit at gcc dot gnu.org
2023-03-22 18:00 ` cvs-commit at gcc dot gnu.org
2023-03-24 18:41 ` cvs-commit at gcc dot gnu.org
2023-03-24 18:44 ` cvs-commit at gcc dot gnu.org
2023-03-24 18:46 ` anlauf at gcc dot gnu.org

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).