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
 [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-2020 The PHP Group
All rights reserved.
Last updated: Sat Mar 28 19:01:27 2020 UTC