Re: PHP 5.4.11 tests: floating point diff

From: Date: Tue, 05 Feb 2013 00:03:20 +0000
Subject: Re: PHP 5.4.11 tests: floating point diff
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-65655@lists.php.net to get a copy of this message
On Tue, 05 Feb 2013 00:12:54 +0100, Levi Morrison <morrison.levi@gmail.com> wrote:

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.
I checked C99 and what it says about this is (7.12.10.1 §3): «The fmod functions return the value x -ny, for some integer n such that, if y is nonzero, the result has the same sign as x...» We can takes clues about whether the sign comment applies to zeros here in 5.4.2.2 §4: «An implementation may give zero and non-numeric values (such as infinities and NaNs) a sign or may leave them unsigned. Wherever such values are unsigned, any requirement in this International Standard to retrieve the sign shall produce an unspecified sign, and any requirement to set the sign shall be ignored.» This would suggest that the sign requirement DOES apply as long as positive and negative zeros exist. While that doesn't follow logically (the last sentence applies to when the values are unsigned), we can follow the principle of "the exception that proves the rule". Therefore, I would be inclined to suggest that this is indeed a bug in math library, but this was just a quick check (may depend on which standards and which versions are followed, etc). -- Gustavo Lopes

Thread (6 messages)

« previous php.internals (#65655) next »