Re: Bug #2835 Updated: floor (8.28 * 100) = 8.27

From: Date: Fri, 26 Nov 1999 21:44:25 +0000
Subject: Re: Bug #2835 Updated: floor (8.28 * 100) = 8.27
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-13159@lists.php.net to get a copy of this message
Hello Aulbach, Your problem is that you incorrectly assume the result of the "floor" function. If you read the specification for floor(double x), it quite clearly says that the function rounds x downwards to the nearest integer, returning that value as a double. After the operation of (8.28 * 100), the nearest integer downwards is 827. Of course, I'm looking at the "C library" specification which I assume PHP utilizes. I even tested your problem in a C program, it exhibits the same behavior, but of course, that is exactly what it is supposed to according to the manual. Jose Friday, November 26, 1999, 9:46:04 AM, you wrote: ID: 2835 User Update by: aulbach@unter.franken.de Status: Closed Bug Type: Misbehaving function Description: floor (8.28 * 100) = 8.27 There are some things which I will say to this good explanation: 1. This was of course clear for me, why this happens. But, sorry, Ramus, I'm not sharing your opinion, that you have to take care about rounding problems by yourself. In my eyes this keeps an error: The function doesn't do, what you expect and the results could be very ugly. See down. 2. The float number was printed out as "828" and not as "827.99999999999999999". So there must be an explizit float conversion, which does it "right". 3. Ok, I understand, why round(9.5) is not 10, but every simple pocket calculator does this simple thing "right". [Or Oracle for example: SQL> select trunc(8.28*100.0,0) from dual; TRUNC(8.28*100,0) ----------------- 828 mySQL of course too.] 4. For this business applications this behavior of the database mow saved me my live, cause I could see, if my change in the program works right: The resulting difference has been above 450 Deutschmark (about $ 200) - this happens when you calculate about 400,000 operations with this small error. If you make this little error every day over a year you pay about $60,000 too much (or too less). Full Bug description available at: http://bugs.php.net/?id=2835 -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net For additional commands, e-mail: php-dev-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.dev (#13159) next »