php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #53523 Missing documentation for edge case of abs() function.
Submitted: 2010-12-11 23:45 UTC Modified: 2010-12-12 04:10 UTC
From: pinja_kolada at yahoo dot com Assigned:
Status: Wont fix Package: Documentation problem
PHP Version: Irrelevant OS: GNU/Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: pinja_kolada at yahoo dot com
New email:
PHP Version: OS:

 

 [2010-12-11 23:45 UTC] pinja_kolada at yahoo dot com
Description:
------------
---
From manual page: http://www.php.net/function.abs
---
Currently return type is described as: 

"The absolute value of number. If the argument number is of type float, the return type is also float, otherwise it is integer (as float usually has a bigger value range than integer)."

and should be something like:

"The absolute value of number. If the argument number is of type float, the return type is also float, otherwise it is integer (as float usually has a bigger value range than integer). If the argument is of type integer with value of - PHP_INT_MAX - 1 (minimum signed integer value) the return type is float due to integer overflow...."

It's an edge case, but can be source of confusion if type is important.

Test script:
---------------
$n = - PHP_INT_MAX - 1;

var_dump($n); // type - int

var_dump(abs($n)); // type - float


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-12 00:22 UTC] dtajchreber@php.net
-Status: Open +Status: Wont fix
 [2010-12-12 00:22 UTC] dtajchreber@php.net
Integer overflow is described here: http://tinyurl.com/38rusjo

It's not really an edge case. It's just how PHP handles overflow. None of the 
other pages that return an integer specifically talk about it and I don't think 
it's necessary to note just on the abs() page.
 [2010-12-12 04:10 UTC] pinja_kolada at yahoo dot com
Agree with you that it is not necessary to note that just on abs() page. 

For edge case (I am not sure, but) I think that abs() is defined here : ext/standard/math.c from line 263 in PHP 5.3.4 source and it's the only case where, when you feed abs() an integer you get back double (which is integer overflow handling).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 03:01:29 2024 UTC