Re: PHP 5.4.11 tests: floating point diff
| From: | Levi Morrison | Date: | Mon, 04 Feb 2013 23:12:54 +0000 |
| Subject: | Re: PHP 5.4.11 tests: floating point diff | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-65654@lists.php.net to get a copy of this message | ||
>> My understanding of floating point calculations is that -0 and 0 are
>> equivalent, so I can safely ignore the failures. I wanted to first
>> check to make sure that is actually true.
>
>
> No, they are not the same thing for several purposes. For instance, they
> have different serializations. See also:
>
> $ php
> <?php $nz = fmod(-2,2); var_dump(atan2(0., $nz), atan2($nz, $nz));
> float(3.1415926535898)
> float(-3.1415926535898)
>
> So I think you should investigate the cause of the problem (different
> results), rather than ignoring the differences. Possibly the difference lies
> in the Intel math library; in that case, you can either separate the tests
> in two or just ignore the test when compiling with the Intel compiler.
Are the rules for double-precision floats the same in this regard?
I have confirmed that fmod(-2, 2) returns positive zero in icc. I have
asked on their forum if there is a flag or something I can enable to
fix this; it might be a bug. Note that fmodf (for floats, not
doubles) correctly returns -0.