From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 541963858D1E; Sun, 19 Mar 2023 01:46:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 541963858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679190369; bh=0z+5WZhB1IH0jc992AwpDy3LmV8+pWMHOCjW9dLkfww=; h=From:To:Subject:Date:From; b=W6Oo6ovOTiII1c1LYyvoWJfR73NexyeQhb6qk41IuRLGG4OMrUcb7tpk+Qd5ShgAU Htet39IlWnjXJWSAY/Slip5gWAQzWi3GciCETBnoZ0Et/DnElCtpb3gHBbuYwju2rM Vb9cPSF/ETxVunTnD+kp8dY+b15koVA/MV7tqoYw= From: "john.harper at vuw dot ac.nz" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/109186] New: nearest(huge(x),-1.0_kind(x)) half of correct value Date: Sun, 19 Mar 2023 01:46:07 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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 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 =3D h= uge and y =3D -1 this program gave about half the correct result. Ifort gave co= rrect results for the 3 different kinds it has: sp,dp,qp. The program: 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=20 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(2),(dplist(n),dpx(n),n=3D1,ncases) print fmt(3),(eplist(n),epx(n),n=3D1,ncases) print fmt(4),(qplist(n),qpx(n),n=3D1,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=