php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75240 Remainder of $a divided by 1 is always 0
Submitted: 2017-09-21 07:32 UTC Modified: 2017-09-21 07:38 UTC
From: miami at blackcrystal dot net Assigned:
Status: Not a bug Package: Math related
PHP Version: 7.0.23 OS: Ubuntu 16.04.3
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: miami at blackcrystal dot net
New email:
PHP Version: OS:

 

 [2017-09-21 07:32 UTC] miami at blackcrystal dot net
Description:
------------
---
From manual page: http://www.php.net/language.operators.arithmetic
---

PHP7 always returns 0 as remainder after division to 1.

<?php
echo (1 % 1; // 0, ok
echo 1.5 % 1; // 0, must be .5
echo 2.234567 % 1; // 0, must be .234567
?>

Test script:
---------------
<?php
echo (1 % 1) ."\n";
echo (1.5 % 1) ."\n";
echo (2.234567 % 1) ."\n";
?>

Expected result:
----------------
0
.5
.234567

Actual result:
--------------
0
0
0

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-09-21 07:38 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2017-09-21 07:38 UTC] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

> Operands of modulo are converted to integers (by stripping the decimal part)
> before processing. For floating-point modulo, see fmod().
 [2017-09-21 07:39 UTC] sjon at hortensius dot net
The explanation is also in the documentation:

"Operands of modulo are converted to integers (by stripping the decimal part) before processing. For floating-point modulo, see fmod()."
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC