php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #65280 Documentation for decoct() incorrect and decoct() behaves strange with float.
Submitted: 2013-07-17 17:34 UTC Modified: 2016-06-21 15:09 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: ben at chico dot com Assigned: cmb (profile)
Status: Closed Package: Math related
PHP Version: Irrelevant OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
15 - 1 = ?
Subscribe to this entry?

 
 [2013-07-17 17:34 UTC] ben at chico dot com
Description:
------------
Documentation says: 

The largest number that can be converted is 4294967295 in decimal resulting to 
"37777777777".

Test script:
---------------
wget http://www.php.net/manual/en/function.decoct.php

Expected result:
----------------
The largest number that can be converted depends on the platform in use. For 32 
bit platform this is 4294967295 in decimal resulting to "37777777777". For 64 bit 
platforms this is 9223372036854775807 in decimal resulting to 
'777777777777777777777'. 

Actual result:
--------------
The largest number that can be converted is 4294967295 in decimal resulting to 
"37777777777".

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-22 22:12 UTC] yohgaki@php.net
-Summary: Documentation for decoct incorrect +Summary: Documentation for decoct() incorrect and decoct() behaves strange with float. -Status: Open +Status: Verified -Package: Documentation problem +Package: Math related
 [2013-07-22 22:12 UTC] yohgaki@php.net
I suppose decoct() behaves differently on 32/64 bit platforms

Under Linux x86_64
php > foreach(range(60,65) as $v) var_dump(pow(2,$v)-1, decoct(pow(2,$v)-1));
int(1152921504606846975)
string(20) "77777777777777777777"
int(2305843009213693951)
string(21) "177777777777777777777"
int(4611686018427387903)
string(21) "377777777777777777777"
float(9223372036854775808)
string(22) "1000000000000000000000"
float(18446744073709551616)
string(1) "0"
float(36893488147419103232)
string(1) "0"


It behaves strange with float values. Is this expected behavior?

BTW, current "precision" ini setting is too small for 64 bit platforms and PHP 
converts integer to float 
even if it is with in 64 bit integer. To get above result, increase precision.

Changed bug type doc to bug to investigate this behavior.
 [2016-06-21 15:03 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=339437
Log: Fix #65280: Documentation for decoct() incorrect
 [2016-06-21 15:09 UTC] cmb@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: cmb
 [2016-06-21 15:09 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

> It behaves strange with float values. Is this expected behavior?

The current implementation of decoct() accepts a zval and casts it
to long[1]. The result of casting too large floats to int is
undefined[2]. So yes, this is expected behavior.

[1] <https://github.com/php/php-src/blob/php-7.0.7/ext/standard/math.c#L1225-L1228>
[2] <http://php.net/manual/en/language.types.integer.php>
 [2020-02-07 06:07 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=dd7e7851446c4867cb9be8c201066fe43fcc7e29
Log: Fix #65280: Documentation for decoct() incorrect
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 16:01:29 2024 UTC