Re: Mathematical differences?!
| From: | Curt Zirzow | Date: | Thu, 18 Sep 2003 21:31:12 +0000 |
| Subject: | Re: Mathematical differences?! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-163059@lists.php.net to get a copy of this message | ||
* Thus wrote Mario Werner (mario@open-ware.de):
>
> I ported a algorithm from JavaScript to PHP and noticed that PHP outputs a
> different result than JS. For example:
>
> ====================
> t = 0.6255264658909423
> f = 20.5
> ln = -6.983333333333333
> d2r = 0.017453292519943295
>
> $ra = (((6.6460656 + 2400.0513 * $t + 2.58e-5 * $t * $t + $f) * 15 - $ln) %
> 360) * $d2r;
>
> PHP outputs 4.4156830075456535
> JS outputs 4.42304792511156
> ====================
>
> I found out that ((...) % 360) returns in PHP 253.0000... whereas JS and a
> Calculator return 253.6085....
> I also tried to use the bc...-functions but the result was the same.
> [...]
> How could that be?! 1:1 the same code but different outputs? Is this a
> PHP-bug? :-?
Nope.
http://bugs.php.net/bug.php?id=12623
fmod() will do what you want.
Curt
--
"I used to think I was indecisive, but now I'm not so sure."