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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mauricio at elmaster dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 14:01:34 2025 UTC