php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23791 Mod doesn't return correct values
Submitted: 2003-05-24 09:58 UTC Modified: 2003-05-25 04:52 UTC
From: info at veebiteenused dot com Assigned:
Status: Wont fix Package: Math related
PHP Version: 4.3.2RC4 OS: RedHat Linux 9
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: info at veebiteenused dot com
New email:
PHP Version: OS:

 

 [2003-05-24 09:58 UTC] info at veebiteenused dot com
long2ip(3232238081) = '192.168.10.-255'

3232238081 % 256 = -255

must be:

3232238081 % 256 = 1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-24 18:04 UTC] derick@php.net
I don't see any problem here, the script below produce the correct output:

[derick@kossu derick]$ php-4.3.2RC4 
<?php
echo long2ip(3232238081);
?>
192.168.10.1

Please submit a valid script that reproduces this problem.

Derick
 [2003-05-24 20:07 UTC] michael dot mauch at gmx dot de
<?php
echo 2147483647 % 1000,"\n";
echo 2147483648 % 1000,"\n";
echo 2147483649 % 1000,"\n";
echo fmod(2147483648,1000),"\n";
?>

Output:

647
-648
-647
648

This is on 32 bit Linux. I'm not sure whether % is supposed to work with numbers bigger than LONG_MAX. 

No problem with long2ip here.
 [2003-05-25 04:52 UTC] derick@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

PHP only supports signed integers (range is -2147483648 to 2147483647 on Linux), so this is actually the expected behavior. We do not 'upgrade' the number to a float automatically because that would be against the nature of the % operator: integer modulo.
 [2003-05-25 04:52 UTC] derick@php.net
Won't fix is a better state.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 12:01:29 2024 UTC