From owner-freebsd-numerics@freebsd.org Mon Jul 23 21:41:22 2018 Return-Path: Delivered-To: freebsd-numerics@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3B2DB105576E for ; Mon, 23 Jul 2018 21:41:22 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail106.syd.optusnet.com.au (mail106.syd.optusnet.com.au [211.29.132.42]) by mx1.freebsd.org (Postfix) with ESMTP id A61ED8FEFB for ; Mon, 23 Jul 2018 21:41:20 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from [192.168.0.102] (c110-21-101-228.carlnfd1.nsw.optusnet.com.au [110.21.101.228]) by mail106.syd.optusnet.com.au (Postfix) with ESMTPS id D6AC53C9B76; Tue, 24 Jul 2018 07:41:18 +1000 (AEST) Date: Tue, 24 Jul 2018 07:41:17 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Steve Kargl cc: enh via freebsd-numerics Subject: Re: fmod nan_mix usage In-Reply-To: <20180723193418.GA66380@troutmask.apl.washington.edu> Message-ID: <20180724071036.O868@besplex.bde.org> References: <20180723193418.GA66380@troutmask.apl.washington.edu> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.2 cv=EseilWUA c=1 sm=1 tr=0 a=PalzARQSbocsUSjMRkwAPg==:117 a=PalzARQSbocsUSjMRkwAPg==:17 a=kj9zAlcOel0A:10 a=F2OS3LCdxiRRRJEjMt0A:9 a=CjuIK1q_8ugA:10 X-BeenThere: freebsd-numerics@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "Discussions of high quality implementation of libm functions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Jul 2018 21:41:22 -0000 On Mon, 23 Jul 2018, Steve Kargl wrote: > On Mon, Jul 23, 2018 at 11:28:08AM -0700, enh via freebsd-numerics wrote: >> the recent change from >> >> return (x*y)/(x*y); >> >> to >> >> return nan_mix(x, y)/nan_mix(x, y); >> >> in e_fmod.c broke some of our unit tests. for example, fmod(3.f, 0.f) in >> one of the VM tests. >> >> bionic/tests/math_test.cpp:(784) Failure in test >> math_h_force_long_double.fmod >> Value of: isnan(fmod(3.0, 0.0)) >> Actual: false >> Expected: true > > Can you share the code for the relevant tests? > This simple program gives the expected results > on amd64. > > #include > #include > > int > main(void) > { > printf("%e %d\n", fmodf(3.f, 0.f), isnan(fmodf(3.f, 0.f))); > printf("%le %d\n", fmod(3.0, 0.0), isnan(fmod(3.0, 0.0))); > printf("%Le %d\n", fmodl(3.L, 0.L), isnan(fmodl(3.L, 0.L))); > return 0; > } > > % cc -o z -O a.c -lm && ./z > nan 1 > nan 1 > nan 1 clang normally evaluates this at compile, so it doesn't test the libary. This is arguably a bug in clang, since it doesn't set the exception flags. #pragma FENV_ACCESS should control this, but it is hard to use and rarely works. The test data needs to be non-literal and perhaps even volatile to prevent the compiler evaluating it at compile time. Bruce