php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30655 mod bug with double
Submitted: 2004-11-02 09:31 UTC Modified: 2004-11-02 10:04 UTC
From: shejan at web dot de Assigned:
Status: Not a bug Package: *General Issues
PHP Version: Irrelevant OS: Linux/Windows
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: shejan at web dot de
New email:
PHP Version: OS:

 

 [2004-11-02 09:31 UTC] shejan at web dot de
Description:
------------
mod (%) has problems with double.
with 2.01*100 mod isnt working
but 1.01*100 works fine.

chaning a double to int isnt working.
chaning a double to string and than int is working.

Reproduce code:
---------------
echo "201%100:  ".(201%100)."<br>"; // 1 (that is right)
echo "(2.01*100)%100:  ".((2.01*100)%100)."<br>"; // 0 (wrong)
echo "((int)(2.01*100))%100:  ".(((int)(2.01*100))%100)."<br>"; // 0 (wrong)
echo "((int)(string)(2.01*100))%100:  ".(((int)(string)(2.01*100))%100)."<br>"; // 1 (right)

Expected result:
----------------
201%100: 1
(2.01*100)%100: 0
((int)(2.01*100))%100: 0
((int)(string)(2.01*100))%100: 1


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-02 10:04 UTC] derick@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: Sun Dec 22 06:01:30 2024 UTC