You are here: Re: Possible bug in round function « PHP Programming Language « IT news, forums, messages
Re: Possible bug in round function

Posted by Andy Hassall on 02/14/06 00:07

On Mon, 13 Feb 2006 22:24:45 +0100, "Janwillem Borleffs" <jw@jwscripts.com>
wrote:

>Andy Hassall wrote:
>> On 5.1.2 it does output 0.23.
>
>Not on my WinXP installation, which produces 0.22
>
>One of the related bug reports (http://bugs.php.net/bug.php?id=35986)
>mentions that this isn't a bug, but due to the limited precision of floats.
>Perhaps it's processor related...

Hum, 0.23 on Linux, 0.22 on Windows 2000. Both are Intel chips. Looks like
there's Windows-specific code in ext/standard/round.c :

#ifndef PHP_ROUND_FUZZ
# ifndef PHP_WIN32
# define PHP_ROUND_FUZZ 0.50000000001
# else
# define PHP_ROUND_FUZZ 0.5
# endif
#endif

#define PHP_ROUND_WITH_FUZZ(val, places) { \
double tmp_val=val, f = pow(10.0, (double) places); \
tmp_val *= f; \
if (tmp_val >= 0.0) { \
tmp_val = floor(tmp_val + PHP_ROUND_FUZZ); \
} else { \
tmp_val = ceil(tmp_val - PHP_ROUND_FUZZ); \
} \
tmp_val /= f; \
val = !zend_isnan(tmp_val) ? tmp_val : val; \
} \


Shame there's no comments explaining what this is there for.

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация