Re: Testing math functions

From: Date: Wed, 29 Aug 2007 15:20:47 +0000
Subject: Re: Testing math functions
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-31965@lists.php.net to get a copy of this message
Pierre wrote:
On 8/23/07, Zoe Slattery <zoe.slattery@googlemail.com> wrote:
Hi - I've writing a few tests for the math extension and have a question about floating point precision. Here's a small example: --TEST-- Test return type and value for expected input sin() --INI-- precision = 14 --FILE-- <?php $threesixty = pi() * 2.0; echo "sin 360 = "; var_dump(sin($threesixty)); ?> --EXPECT-- sin 360 = float(-2.4492127076448E-16) Is it right to test for an exact number in this way? I was slightly suprised that I got the same number from Windows and Linux (maybe I shouldn't be). If not, I could write the test above to check that sin 360 is zero plus/minus some small number - but how small?
    
It really depends on the architecture. Using a precision of 10 should put you on the safe side, at least for the common architecture (intel, amd and ppc). Yes - you are right thanks. I'm currently testing that the answer is within +/- 1.0E-10 of what I expect - that works on the processor architectures that I have access to. I guess I'll find out what happens on the others wheh I check the test cases in :-).
--Pierre


« previous php.internals (#31965) next »