From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7AF743858D35; Sun, 19 Mar 2023 08:47:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7AF743858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679215626; bh=sItBVm2QqF4LcxZdbMrnkEHkLnzu3bVuEi2bvPqJ8uo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=phqu3t5tmv+cRiq+apI3aDs6AKJWVv2nNW8C0EZjNaHp6y/TOC8YW+gV4Tci6bBes 5fHDaAjH9oNL/Wa3qc949UQjpq1uIMcAuyyh271WFovz+qbdqNqKcV8YlrMTdzTZ1w ZThSPFO9n0aHa2YBPcNmua2BU++euOViwxlHyLWc= From: "john.harper at vuw dot ac.nz" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/109186] nearest(huge(x),-1.0_kind(x)) half of correct value Date: Sun, 19 Mar 2023 08:47:06 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: john.harper at vuw dot ac.nz X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109186 --- Comment #2 from john.harper at vuw dot ac.nz --- The results I expected were that nearest(huge(sp1),-sp1) would be near huge(sp1)/(1+epsilon(sp1)), nearest(huge(dp1),-dp1) would be near huge(dp1)/(1+epsilon(dp1)), nearest(huge(ep1),-ep1) would be near huge(ep1)/(1+epsilon(ep1)), nearest(huge(qp1),-qp1) would be near huge(qp1)/(1+epsilon(qp1)). The results from gfortran were different from those by a factor near 2. On compiling with ifort I got results close to what I had expected, which is why I thought the bug was not in my program. The g95 compiler (now=20 about 10 years old) gave results identical to those of ifort except for ep =3D selected_real_kind(18) which ifort treats as if it were=20 selected_real_kind(33) because ifort has only three real kinds. By the way I thought I was using gfortran 12.0. Compiling with -v said GNU Fortran (Ubuntu 12.1.0-2ubuntu1~22.04) version 12.1.0=20 (x86_64-linux-gnu) I wish to apologise for that error in my bug report. I got the same output on another machine with GNU Fortran (GCC) version 12.2.0=20 (x86_64-pc-linux-gnu) The factor 2 discrepancies become clearer in this version of my program, which has 4 more lines printing huge/nearest for the 4 real kinds. program nearesttest3 implicit none integer,parameter::sp =3D kind(1.0), dp=3Dkind(1d0), ncases =3D 2, & ep =3D selected_real_kind(18),qp =3D selected_real_kind(33) character(*),parameter:: fmt(4) =3D & "(A,ES"//["16.08E2","26.17E3","30.20E4","44.34E4"]//")" character(24),dimension(2):: splist,dplist,eplist,qplist integer n real(sp),parameter::sp1 =3D 1.0_sp real(sp):: spx(ncases) =3D [huge(sp1),nearest(huge(sp1),-sp1)] data splist/'huge(sp1)','nearest(huge(sp1),-sp1)'/ real(dp),parameter::dp1 =3D 1.0_dp real(dp):: dpx(ncases) =3D [huge(dp1),nearest(huge(dp1),-dp1)] data dplist/'huge(dp1)','nearest(huge(dp1),-dp1)'/ real(ep),parameter::ep1 =3D 1.0_ep real(ep):: epx(ncases) =3D [huge(ep1),nearest(huge(ep1),-ep1)] data eplist/'huge(ep1)','nearest(huge(ep1),-ep1)'/ real(qp),parameter::qp1 =3D 1.0_qp real(qp):: qpx(ncases) =3D [huge(qp1),nearest(huge(qp1),-qp1)] data qplist/'huge(qp1)','nearest(huge(qp1),-qp1)'/ print fmt(1),(splist(n),spx(n),n=3D1,ncases) print fmt(1),'huge/nearest =3D ',huge(sp1)/nearest(huge(sp1),-sp1) print fmt(2),(dplist(n),dpx(n),n=3D1,ncases) print fmt(2),'huge/nearest =3D ',huge(dp1)/nearest(huge(dp1),-dp1) print fmt(3),(eplist(n),epx(n),n=3D1,ncases) print fmt(3),'huge/nearest =3D ',huge(ep1)/nearest(huge(ep1),-ep1) print fmt(4),(qplist(n),qpx(n),n=3D1,ncases) print fmt(4),'huge/nearest =3D ',huge(qp1)/nearest(huge(qp1),-qp1) end program nearesttest3 Its gfortran output: huge(sp1) 3.40282347E+38 nearest(huge(sp1),-sp1) 1.70141173E+38 huge/nearest =3D 2.00000000E+00 huge(dp1) 1.79769313486231571E+308 nearest(huge(dp1),-dp1) 8.98846567431157854E+307 huge/nearest =3D 2.00000000000000000E+000 huge(ep1) 1.18973149535723176502E+4932 nearest(huge(ep1),-ep1) 5.94865747678615882511E+4931 huge/nearest =3D 2.00000000000000000000E+0000 huge(qp1) 1.1897314953572317650857593266280070E+4932 nearest(huge(qp1),-qp1) 5.9486574767861588254287966331400351E+4931 huge/nearest =3D 2.0000000000000000000000000000000000E+0000 Its g95 output: uge(sp1) 3.40282347E+38 nearest(huge(sp1),-sp1) 3.40282326E+38 huge/nearest =3D 1.00000012E+00 huge(dp1) 1.79769313486231571E+308 nearest(huge(dp1),-dp1) 1.79769313486231551E+308 huge/nearest =3D 1.00000000000000022E+000 huge(ep1) 1.18973149535723176502E+4932 nearest(huge(ep1),-ep1) 1.18973149535723176496E+4932 huge/nearest =3D 1.00000000000000000011E+0000 huge(qp1) 1.1897314953572317650857593266280070E+4932 nearest(huge(qp1),-qp1) 1.1897314953572317650857593266280069E+4932 huge/nearest =3D 1.0000000000000000000000000000000002E+0000 On Sun, 19 Mar 2023, jvdelisle at gcc dot gnu.org wrote: > Date: Sun, 19 Mar 2023 05:06:47 +0000 > From: jvdelisle at gcc dot gnu.org > To: John Harper > Subject: [Bug fortran/109186] nearest(huge(x), > -1.0_kind(x)) half of correct value > Resent-Date: Sun, 19 Mar 2023 18:06:59 +1300 (NZDT) > Resent-From: >=20 > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109186 > > Jerry DeLisle changed: > > What |Removed |Added > -------------------------------------------------------------------------= --- > CC| |jvdelisle at gcc dot gnu.= org > > --- Comment #1 from Jerry DeLisle --- > Can you clarify what you expect the correct results should be that you ex= pect? > > --=20 > You are receiving this mail because: > You reported the bug. > -- John Harper, School of Mathematics and Statistics Victoria Univ. of Wellington, PO Box 600, Wellington 6140, New Zealand. e-mail john.harper@vuw.ac.nz phone +64(0) 4 463 5276=