svn: /phpdoc/en/trunk/reference/misc/functions/ pack.xml
| From: | Gustavo André dos Santos Lopes | Date: | Sun, 05 Sep 2010 09:59:08 +0000 |
| Subject: | svn: /phpdoc/en/trunk/reference/misc/functions/ pack.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-7060@lists.php.net to get a copy of this message | ||
cataphract Sun, 05 Sep 2010 09:59:08 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=303052
Log:
- Expanding on the large integers values and unsigned types. Tangentially related to bug #52729.
Bug: http://bugs.php.net/52729 (Open) unpack() format I, L,
N and V returns negative value
Changed paths:
U phpdoc/en/trunk/reference/misc/functions/pack.xml
Modified: phpdoc/en/trunk/reference/misc/functions/pack.xml
===================================================================
--- phpdoc/en/trunk/reference/misc/functions/pack.xml 2010-09-05 09:29:37 UTC (rev 303051)
+++ phpdoc/en/trunk/reference/misc/functions/pack.xml 2010-09-05 09:59:08 UTC (rev 303052)
@@ -5,7 +5,7 @@
<refname>pack</refname>
<refpurpose>Pack data into binary string</refpurpose>
</refnamediv>
-
+
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
@@ -29,14 +29,8 @@
function <function>pack</function> gives the same result for
signed and unsigned format codes.
</para>
- <para>
- Also note that PHP internally stores <type>integer</type> values as
- signed values of a machine-dependent size. If you give it an unsigned
- integer value too large to be stored that way it is converted to a
- <type>float</type> which often yields an undesired result.
- </para>
</refsect1>
-
+
<refsect1 role="parameters">
&reftitle.parameters;
<para>
@@ -159,14 +153,14 @@
</variablelist>
</para>
</refsect1>
-
+
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns a binary string containing data.
</para>
</refsect1>
-
+
<refsect1 role="examples">
&reftitle.examples;
<para>
@@ -186,7 +180,34 @@
</example>
</para>
</refsect1>
-
+
+ <refsect1 role="notes">
+ &reftitle.notes;
+ <caution>
+ <para>Note that PHP internally stores <type>integer</type> values as
+ signed values of a machine-dependent size (C type <literal>long</literal>).
+ Integer literals and operations that yield numbers outside the bounds of the
+ <type>integer</type> type will be stored as <type>float</type>.
+ When packing these floats as integers, they are first cast into the integer
+ type. This may or may not result in the desired byte pattern.
+ </para>
+ <para>The most relevant case is when packing unsigned numbers that would
+ be representable with the <type>integer</type> type if it were unsigned.
+ In systems where the <type>integer</type> type has a 32-bit size, the cast
+ usually results in the same byte pattern as if the <type>integer</type> were
+ unsigned (although this relies on implementation-defined unsigned to signed
+ conversions, as per the C standard). In systems where the
+ <type>integer</type> type has 64-bit size, the <type>float</type> most
+ likely does not have a mantissa large enough to hold the value without
+ loss of precision. If those systems also have a native 64-bit C
+ <literal>int</literal> type (most UNIX-like systems don't), the only way to
+ use the <literal>I</literal> pack format in the upper range is to create
+ <type>integer</type> negative values with the same byte representation
+ as the desired unsigned value.
+ </para>
+ </caution>
+ </refsect1>
+
<refsect1 role="seealso">
&reftitle.seealso;
<para>
@@ -195,7 +216,7 @@
</simplelist>
</para>
</refsect1>
-
+
</refentry>
<!-- Keep this comment at the end of the file