php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30614 Adding floating numbers fails
Submitted: 2004-10-29 19:21 UTC Modified: 2004-10-29 20:17 UTC
From: mauricio at elmaster dot com Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: 5.0.1 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
16 + 1 = ?
Subscribe to this entry?

 
 [2004-10-29 19:21 UTC] mauricio at elmaster dot com
Description:
------------
This simple operation fails. We have tried it on PHP 4.3.4 standard install on fedora Core 2, and PHP 5.0.1.

Instead of 0 we get 1-8.8817841970013E-16. If we change a bit the number the code doesn't fails, very weird.

Reproduce code:
---------------
<?php
  die(9.95 + 4.97 - 9.95 - 4.97);
                                                                                                                             ?>

Expected result:
----------------
0

Actual result:
--------------
1-8.8817841970013E-16

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-29 20:17 UTC] magnus@php.net
Floating point values have a limited precision. Hence a value might 
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly 
printing it without any mathematical operations.
 
Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 09:01:28 2024 UTC