From owner-freebsd-numerics@freebsd.org Mon Jul 23 21:30:50 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 170751055469 for ; Mon, 23 Jul 2018 21:30:50 +0000 (UTC) (envelope-from enh@google.com) Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5D20D8F8D3 for ; Mon, 23 Jul 2018 21:30:49 +0000 (UTC) (envelope-from enh@google.com) Received: by mail-lj1-x22c.google.com with SMTP id f8-v6so1793721ljk.1 for ; Mon, 23 Jul 2018 14:30:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gmCcFvCxUYx0PnwnChdBWsP2oDlYFZjROxlEg9n6sfU=; b=a1KBxZSTmEl5oGjFqYqjCWs1v/JzF0jP2y09YQtffpyYxQTid7d6A+y0M0KccXhyGo EJ9BQAZwe4+/dWLmiQ1uA7/SAyvgWAU8V0B3VWK8cYTsr2jzwXPYRBGa/mxWXgEHqPIo JPZpy/99INMk14E9HMOgmXoH/jipR3brtFbpK11O/O7dl3SqqEDKZgFmG6LXdklIUiCz WuahwVaiD5CHLvOktUWzC5H09scPHX+Uzyy2+Y14PmKq8I9cMZpxAVLMZfS8z+MfQqdt unFuEooQY4WW0S3MRLbaQYyDa2gZ6Tp3QFwUTm7FsfxIBZ+bwekos7vWh0Zt6XQ5IdAN e6sQ== X-Gm-Message-State: AOUpUlHrWlTdMUwS6R7BeGWoB4C691rRDjyx3U+WAobqQ96hLp/Q9QlD 2ADIDU4d/+JOSWaBGvy+6ztxk2FwUMTB1oMzA3Vmh5sw7cYxaQ== X-Google-Smtp-Source: AAOMgpfnzLgNwIGJddRUNy/sjH0vIHc8BZe952bJhOT+rovWiF3YptYKm5/ilkb0NaBBWVo3AGOo5uraw9Rffri7qfg= X-Received: by 2002:a2e:750d:: with SMTP id q13-v6mr9615909ljc.148.1532381447582; Mon, 23 Jul 2018 14:30:47 -0700 (PDT) MIME-Version: 1.0 References: <20180724050141.Q2280@besplex.bde.org> In-Reply-To: <20180724050141.Q2280@besplex.bde.org> From: enh Date: Mon, 23 Jul 2018 14:30:35 -0700 Message-ID: Subject: Re: fmod nan_mix usage To: brde@optusnet.com.au Cc: freebsd-numerics@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.27 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:30:50 -0000 On Mon, Jul 23, 2018 at 12:54 PM Bruce Evans wrote: > On Mon, 23 Jul 2018, 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. > > This is a bug in my change. > > nan_mix(x, y) does essentially x+y, but here essentially x*y is needed so > that y = 0 gives 0 unless x is NaN. In the example, adding gives 3 instead > of 0, so the final result is 1 instead of 0.0/0.0 = NaN. > > The log message mentions avoiding this problem in s_ccosh[fl].c and > s_sinh[fl].c. This list was supposed have all special cases. > > Unfortunately, this seems to prevent use of a single macro. I will try > using a 2 macros with 1 using sums and the other products. The non-broken > cases converted sums to sums. > > > 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 > > math_h_force_long_double.fmod exited with exitcode 1. > > [ FAILED ] math_h_force_long_double.fmodf (13 ms) > > bionic/tests/math_test.cpp:(798) Failure in test > > math_h_force_long_double.fmodf > > Value of: isnanf(fmodf(3.0f, 0.0f)) > > Actual: false > > Expected: true > > math_h_force_long_double.fmodf exited with exitcode 1. > > [ FAILED ] math_h_force_long_double.fmodl (12 ms) > > bionic/tests/math_test.cpp:(812) Failure in test > > math_h_force_long_double.fmodl > > Value of: isnanl(fmodl(3.0L, 0.0L)) > > Actual: false > > Expected: true > > Do you have a lot of special tests like this? I mostly use generic tests > that don't assert any particular result, but compare the results in > different precisions. I apparently changed all precisions to be > consistently wrong at the same time. > bionic doesn't have as many as it should, though i do add them any time we catch a regression. all our tests are in https://android.googlesource.com/platform/bionic/+/master/tests/ with complex_test.cpp and math_test.cpp being the interesting ones. (complex_test.cpp is laughably perfunctory right now, but sadly *did* catch bugs where historically the makefiles were broken and we weren't shipping all the functions for all the architectures.) i do try to ensure that we use the BSD rather than APL2 license for the tests, though apparently i failed in both these cases. i'll fix the headers if that helps. i don't think the contributed Android tests in math_data/ are very high quality. i have no reason to believe they're not just random numbers (and glibc fails several of them, and i don't know who's right in those cases). the external/arm-optimized-routines project (corresponding to https://github.com/ARM-software/optimized-routines) has much better tests (for those functions they support) and clearly distinguish between directed and random testing: https://github.com/ARM-software/optimized-routines/tree/master/test/testcases > > it looks like e_remainder.c might have the same issue, but Android's > tests > > didn't catch that :-( i'll improve the tests... > > Indeed. Also remquo* and ctanh* :-(. ctanh* should be more like csinh* > and ccosh*, and it was. > yeah, i caught remquo after i hit send (and have just uploading a CL with the missing tests). i'm glad to hear that ctanh* actually works because i'd failed to break it :-) i'll commit those extra tests too anyway. (strictly, the netbsd ctanhl we use is broken for the NaN+0i case, returning NaN+NaNi rather than NaN+0i, but that's not your fault, other than that i'll switch to the freebsd ld128 ctanhl as soon as it exists :-) ) > The only other complicated case seems to be hypot[fl](). This subtracts > instead of adds, since it wants to convert Inf-Inf to NaN. > hypot seems okay from my testing. am i missing another test? > Bruce >