On Thu, August 23, 2007 10:28 am, Zoe Slattery 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?

Seems to me that if 'precision' setting is supposed to affect the
output of your calculations, then you should, in theory, be able to
rely on 14 decimal places, no?...

I realize that's an over-simplistic answer, perhaps, and I thought the
precision only applied to BC_MATH and/or GMP calculations.

I'd be surprised if it was ALWAYS right for every OS, and I strongly
suspect it's going to fail on 64-bit hardware big-time.

I guess the first question I have is "What precisely are you testing?"

The 'precision' setting?

Or just that sin(2 * M_PI) is kinda sorta close to 0?

If you just want "close to 0" then double the answer you are getting
now, and call that "close enough" :-)

If you think 'precision' is supposed to affect it and guarantee 14
decimal places of precision, then 1.0E-14 to 1.0E14 should be your
range, no?

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to