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
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: 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: Sun Dec 22 02:01:28 2024 UTC