cvs: phpdoc /en/reference/math/functions bindec.xml
| From: | Daniel Convissor | Date: | Tue, 14 Apr 2009 22:33:00 +0000 |
| Subject: | cvs: phpdoc /en/reference/math/functions bindec.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-3719@lists.php.net to get a copy of this message | ||
danielc Tue Apr 14 22:33:00 2009 UTC
Modified files:
/phpdoc/en/reference/math/functions bindec.xml
Log:
* Use precision ini setting to simplify the example.
http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/math/functions/bindec.xml?r1=1.14&r2=1.15&diff_format=u
Index: phpdoc/en/reference/math/functions/bindec.xml
diff -u phpdoc/en/reference/math/functions/bindec.xml:1.14
phpdoc/en/reference/math/functions/bindec.xml:1.15
--- phpdoc/en/reference/math/functions/bindec.xml:1.14 Tue Apr 14 14:53:47 2009
+++ phpdoc/en/reference/math/functions/bindec.xml Tue Apr 14 22:32:59 2009
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.14 $ -->
+<!-- $Revision: 1.15 $ -->
<refentry xml:id="function.bindec" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>bindec</refname>
@@ -111,27 +111,31 @@
$magnitude_lower = pow(2, (PHP_INT_SIZE * 8) - 2);
p($magnitude_lower - 1);
-p($magnitude_lower, 'see the rollover?');
+p($magnitude_lower, 'See the rollover? Watch it next time around...');
p(PHP_INT_MAX, 'PHP_INT_MAX');
p(~PHP_INT_MAX, 'interpreted to be one more than PHP_INT_MAX');
-p(-1, 'interpreted to be the largest unsigned integer');
-function p($input, $note = '') {
- $format = '%0' . (PHP_INT_SIZE * 8) . 'b';
+if (PHP_INT_SIZE == 4) {
+ $note = 'interpreted to be the largest unsigned integer';
+} else {
+ $note = 'interpreted to be the largest unsigned integer
+ (18446744073709551615) but skewed by float precision';
+}
+p(-1, $note);
+
+function p($input, $note = '') {
echo "input: $input\n";
+
+ $format = '%0' . (PHP_INT_SIZE * 8) . 'b';
$bin = sprintf($format, $input);
echo "binary: $bin\n";
+ ini_set('precision', 20); // For readability on 64 bit boxes.
$dec = bindec($bin);
echo 'bindec(): ' . $dec . "\n";
- if (PHP_INT_SIZE == 8) {
- echo 'dec as float: ' . sprintf('%f', $dec) . "\n";
- echo "64 bit note: float lacks precision in this range\n";
- }
-
if ($note) {
echo "NOTE: $note\n";
}
@@ -151,7 +155,7 @@
input: 1073741824
binary: 01000000000000000000000000000000
bindec(): 1073741824
-NOTE: see the rollover?
+NOTE: See the rollover? Watch it next time around...
input: 2147483647
binary: 01111111111111111111111111111111
@@ -175,36 +179,27 @@
input: 4611686018427387903
binary: 0011111111111111111111111111111111111111111111111111111111111111
bindec(): 4611686018427387903
-dec as float: 4611686018427387904.000000
-64 bit note: float lacks precision in this range
input: 4611686018427387904
binary: 0100000000000000000000000000000000000000000000000000000000000000
bindec(): 4611686018427387904
-dec as float: 4611686018427387904.000000
-64 bit note: float lacks precision in this range
-NOTE: see the rollover?
+NOTE: See the rollover? Watch it next time around...
input: 9223372036854775807
binary: 0111111111111111111111111111111111111111111111111111111111111111
bindec(): 9223372036854775807
-dec as float: 9223372036854775808.000000
-64 bit note: float lacks precision in this range
NOTE: PHP_INT_MAX
input: -9223372036854775808
binary: 1000000000000000000000000000000000000000000000000000000000000000
-bindec(): 9.2233720368548E+18
-dec as float: 9223372036854775808.000000
-64 bit note: float lacks precision in this range
+bindec(): 9223372036854775808
NOTE: interpreted to be one more than PHP_INT_MAX
input: -1
binary: 1111111111111111111111111111111111111111111111111111111111111111
-bindec(): 1.844674407371E+19
-dec as float: 18446744073709551616.000000
-64 bit note: float lacks precision in this range
+bindec(): 18446744073709551616
NOTE: interpreted to be the largest unsigned integer
+ (18446744073709551615) but skewed by float precision
]]>
</screen>
</example>