php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70009 modulus operator error
Submitted: 2015-07-07 10:21 UTC Modified: 2015-07-07 10:21 UTC
From: s7sunder at gmail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.6.11RC1 OS: LINUX UBUNTU 14.04
Private report: No CVE-ID: None
 [2015-07-07 10:21 UTC] s7sunder at gmail dot com
Description:
------------
Why these 2 values are not returning the true

var_dump((1.005*1000)%5==0); //boolean false
var_dump((1.015*1000)%5==0); //boolean false

Remaining values are correct.

Test script:
---------------
<?php 

//These 2 are not returning the expected results
var_dump((1.005*1000)%5==0); //boolean false
var_dump((1.015*1000)%5==0); //boolean false


var_dump((1.005*1000)%5==0); //boolean false
var_dump((1.010*1000)%5==0); //boolean true
var_dump((1.015*1000)%5==0); //boolean false
var_dump((1.020*1000)%5==0); //boolean true
var_dump((1.025*1000)%5==0); //boolean true
var_dump((1.030*1000)%5==0); //boolean true
var_dump((1.035*1000)%5==0); //boolean true
var_dump((1.035*1000)%5==0); //boolean true
var_dump((1.040*1000)%5==0); //boolean true
var_dump((1.045*1000)%5==0); //boolean true
var_dump((1.050*1000)%5==0); //boolean true
var_dump((1.055*1000)%5==0); //boolean true
var_dump((1.060*1000)%5==0); //boolean true
var_dump((1.065*1000)%5==0); //boolean true
var_dump((1.070*1000)%5==0); //boolean true
var_dump((1.075*1000)%5==0); //boolean true
var_dump((1.080*1000)%5==0); //boolean true
var_dump((1.085*1000)%5==0); //boolean true
var_dump((1.090*1000)%5==0); //boolean true
var_dump((1.095*1000)%5==0); //boolean true
var_dump((1.100*1000)%5==0); //boolean true


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-07 10:21 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2015-07-07 10:21 UTC] requinix@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.

If you would like to know more about "floats" and what IEEE
754 is, read this:
http://www.floating-point-gui.de/

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 11:01:29 2024 UTC