[DOC-CVS] [doc-en] master: Enable WASM for book.math, and tweak examples
[email protected] (Derick Rethans)
| Newsgroups | php.doc.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: Derick Rethans (derickr)
Date: 2025-05-06T16:59:37+01:00
Commit: https://github.com/php/doc-en/commit/761d72245071f89a626903c9bcdc6aaff1252d54
Raw diff: https://github.com/php/doc-en/commit/761d72245071f89a626903c9bcdc6aaff1252d54.diff
Enable WASM for book.math, and tweak examples
Changed paths:
M reference/math/book.xml
M reference/math/functions/ceil.xml
M reference/math/functions/deg2rad.xml
M reference/math/functions/exp.xml
M reference/math/functions/floor.xml
M reference/math/functions/fmod.xml
M reference/math/functions/hexdec.xml
M reference/math/functions/intdiv.xml
M reference/math/functions/max.xml
M reference/math/functions/min.xml
M reference/math/functions/pi.xml
M reference/math/functions/pow.xml
M reference/math/functions/sin.xml
M reference/math/functions/sqrt.xml
Diff:
diff --git a/reference/math/book.xml b/reference/math/book.xml
index 7f1ce4ce0ce5..6b0b3a654bba 100644
--- a/reference/math/book.xml
+++ b/reference/math/book.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
-<book xml:id="book.math" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
+<book xml:id="book.math" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" annotations="interactive">
<?phpdoc extension-membership="core" ?>
<title>Mathematical Functions</title>
<titleabbrev>Math</titleabbrev>
diff --git a/reference/math/functions/ceil.xml b/reference/math/functions/ceil.xml
index 927d7a88d0d8..a4be110b323d 100644
--- a/reference/math/functions/ceil.xml
+++ b/reference/math/functions/ceil.xml
@@ -73,9 +73,9 @@
<programlisting role="php">
<![CDATA[
<?php
-echo ceil(4.3); // 5
-echo ceil(9.999); // 10
-echo ceil(-3.14); // -3
+echo ceil(4.3), PHP_EOL; // 5
+echo ceil(9.999), PHP_EOL; // 10
+echo ceil(-3.14), PHP_EOL; // -3
?>
]]>
</programlisting>
diff --git a/reference/math/functions/deg2rad.xml b/reference/math/functions/deg2rad.xml
index 37088bd3d01d..1c4b17964c42 100644
--- a/reference/math/functions/deg2rad.xml
+++ b/reference/math/functions/deg2rad.xml
@@ -48,7 +48,7 @@
<![CDATA[
<?php
-echo deg2rad(45); // 0.785398163397
+echo deg2rad(45), PHP_EOL; // 0.785398163397
var_dump(deg2rad(45) === M_PI_4); // bool(true)
?>
diff --git a/reference/math/functions/exp.xml b/reference/math/functions/exp.xml
index a31723a89866..6777d1a4fe19 100644
--- a/reference/math/functions/exp.xml
+++ b/reference/math/functions/exp.xml
@@ -50,7 +50,7 @@
<programlisting role="php">
<![CDATA[
<?php
-echo exp(12) . "\n";
+echo exp(12), PHP_EOL;
echo exp(5.7);
?>
]]>
@@ -58,8 +58,8 @@ echo exp(5.7);
&example.outputs;
<screen>
<![CDATA[
-1.6275E+005
-298.87
+162754.791419
+298.86740096706
]]>
</screen>
</example>
diff --git a/reference/math/functions/floor.xml b/reference/math/functions/floor.xml
index d53facfa5b6f..db7a3f87c1ef 100644
--- a/reference/math/functions/floor.xml
+++ b/reference/math/functions/floor.xml
@@ -71,9 +71,9 @@
<programlisting role="php">
<![CDATA[
<?php
-echo floor(4.3); // 4
-echo floor(9.999); // 9
-echo floor(-3.14); // -4
+echo floor(4.3), PHP_EOL; // 4
+echo floor(9.999), PHP_EOL; // 9
+echo floor(-3.14), PHP_EOL; // -4
?>
]]>
</programlisting>
diff --git a/reference/math/functions/fmod.xml b/reference/math/functions/fmod.xml
index f2d8b9371de7..7024367147b1 100644
--- a/reference/math/functions/fmod.xml
+++ b/reference/math/functions/fmod.xml
@@ -65,6 +65,8 @@ $x = 5.7;
$y = 1.3;
$r = fmod($x, $y);
// $r equals 0.5, because 4 * 1.3 + 0.5 = 5.7
+
+var_dump($x, $y, $r);
?>
]]>
</programlisting>
diff --git a/reference/math/functions/hexdec.xml b/reference/math/functions/hexdec.xml
index 6a3aa36a3b01..8231e1b0b698 100644
--- a/reference/math/functions/hexdec.xml
+++ b/reference/math/functions/hexdec.xml
@@ -76,12 +76,21 @@
<programlisting role="php">
<![CDATA[
<?php
-var_dump(hexdec("See"));
-var_dump(hexdec("ee"));
-// both print "int(238)"
-
+var_dump(hexdec("ee")); // prints "int(238)"
+var_dump(hexdec("a0")); // prints "int(160)"
+?>
+]]>
+ </programlisting>
+ </example>
+ </para>
+ <para>
+ <example>
+ <title><function>hexdec</function> with Invalid Characters</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+var_dump(hexdec("See")); // print "int(238)"
var_dump(hexdec("that")); // print "int(10)"
-var_dump(hexdec("a0")); // print "int(160)"
?>
]]>
</programlisting>
diff --git a/reference/math/functions/intdiv.xml b/reference/math/functions/intdiv.xml
index 0892a58e76f5..c9ec38fa14ea 100644
--- a/reference/math/functions/intdiv.xml
+++ b/reference/math/functions/intdiv.xml
@@ -66,11 +66,10 @@ var_dump(intdiv(3, -2));
var_dump(intdiv(-3, -2));
var_dump(intdiv(PHP_INT_MAX, PHP_INT_MAX));
var_dump(intdiv(PHP_INT_MIN, PHP_INT_MIN));
-var_dump(intdiv(PHP_INT_MIN, -1));
-var_dump(intdiv(1, 0));
?>
]]>
</programlisting>
+ &example.outputs;
<screen>
<![CDATA[
int(1)
@@ -79,9 +78,35 @@ int(-1)
int(1)
int(1)
int(1)
+]]>
+ </screen>
+ </example>
+ </para>
+ <para>
+ <example>
+ <title><function>intdiv</function> Example With Invalid Divisor</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+try {
+ intdiv(PHP_INT_MIN, -1);
+} catch (Error $e) {
+ echo get_class($e), ': ', $e->getMessage(), PHP_EOL;
+}
-Fatal error: Uncaught ArithmeticError: Division of PHP_INT_MIN by -1 is not an integer in %s on line 8
-Fatal error: Uncaught DivisionByZeroError: Division by zero in %s on line 9
+try {
+ intdiv(1, 0);
+} catch (Error $e) {
+ echo get_class($e), ': ', $e->getMessage(), PHP_EOL;
+}
+?>
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+ArithmeticError: Division of PHP_INT_MIN by -1 is not an integer
+DivisionByZeroError: Division by zero
]]>
</screen>
</example>
diff --git a/reference/math/functions/max.xml b/reference/math/functions/max.xml
index be350a5be0b1..2dd7e3c7896d 100644
--- a/reference/math/functions/max.xml
+++ b/reference/math/functions/max.xml
@@ -127,30 +127,35 @@
<programlisting role="php">
<![CDATA[
<?php
-echo max(2, 3, 1, 6, 7); // 7
-echo max(array(2, 4, 5)); // 5
+echo max(2, 3, 1, 6, 7), PHP_EOL; // 7
+echo max(array(2, 4, 5)), PHP_EOL; // 5
// Here we are comparing -1 < 0, so 'hello' is the highest value
-echo max('hello', -1); // hello
+echo max('hello', -1), PHP_EOL; // hello
// With multiple arrays of different lengths, max returns the longest
$val = max(array(2, 2, 2), array(1, 1, 1, 1)); // array(1, 1, 1, 1)
+var_dump($val);
// Multiple arrays of the same length are compared from left to right
// so in our example: 2 == 2, but 5 > 4
$val = max(array(2, 4, 8), array(2, 5, 1)); // array(2, 5, 1)
+var_dump($val);
// If both an array and non-array are given, the array will be returned
// as comparisons treat arrays as greater than any other value
$val = max('string', array(2, 5, 7), 42); // array(2, 5, 7)
+var_dump($val);
// If one argument is NULL or a boolean, it will be compared against
// other values using the rule FALSE < TRUE regardless of the other types involved
// In the below example, -10 is treated as TRUE in the comparison
$val = max(-10, FALSE); // -10
+var_dump($val);
// 0, on the other hand, is treated as FALSE, so is "lower than" TRUE
$val = max(0, TRUE); // TRUE
+var_dump($val);
?>
]]>
</programlisting>
diff --git a/reference/math/functions/min.xml b/reference/math/functions/min.xml
index b2c03c6ac166..c440f4c2dc12 100644
--- a/reference/math/functions/min.xml
+++ b/reference/math/functions/min.xml
@@ -127,32 +127,39 @@
<programlisting role="php">
<![CDATA[
<?php
-echo min(2, 3, 1, 6, 7); // 1
-echo min(array(2, 4, 5)); // 2
+echo min(2, 3, 1, 6, 7), PHP_EOL; // 1
+echo min(array(2, 4, 5)), PHP_EOL; // 2
// Here we are comparing -1 < 0, so -1 is the lowest value
-echo min('hello', -1); // -1
+echo min('hello', -1), PHP_EOL; // -1
// With multiple arrays of different lengths, min returns the shortest
$val = min(array(2, 2, 2), array(1, 1, 1, 1)); // array(2, 2, 2)
+var_dump($val);
// Multiple arrays of the same length are compared from left to right
// so in our example: 2 == 2, but 4 < 5
$val = min(array(2, 4, 8), array(2, 5, 1)); // array(2, 4, 8)
+var_dump($val);
// If both an array and non-array are given, the array is never returned
// as comparisons treat arrays as greater than any other value
$val = min('string', array(2, 5, 7), 42); // string
+var_dump($val);
// If one argument is NULL or a boolean, it will be compared against
// other values using the rules FALSE < TRUE and NULL == FALSE regardless of the
// other types involved
// In the below examples, both -10 and 10 are treated as TRUE in the comparison
$val = min(-10, FALSE, 10); // FALSE
+var_dump($val);
+
$val = min(-10, NULL, 10); // NULL
+var_dump($val);
// 0, on the other hand, is treated as FALSE, so is "lower than" TRUE
$val = min(0, TRUE); // 0
+var_dump($val);
?>
]]>
</programlisting>
diff --git a/reference/math/functions/pi.xml b/reference/math/functions/pi.xml
index 73605764fea2..ada2f1fdf825 100644
--- a/reference/math/functions/pi.xml
+++ b/reference/math/functions/pi.xml
@@ -37,8 +37,8 @@
<programlisting role="php">
<![CDATA[
<?php
-echo pi(); // 3.1415926535898
-echo M_PI; // 3.1415926535898
+echo pi(), PHP_EOL; // 3.1415926535898
+echo M_PI, PHP_EOL; // 3.1415926535898
?>
]]>
</programlisting>
diff --git a/reference/math/functions/pow.xml b/reference/math/functions/pow.xml
index 06a491426d3f..e6aedbcb2211 100644
--- a/reference/math/functions/pow.xml
+++ b/reference/math/functions/pow.xml
@@ -94,10 +94,20 @@ var_dump(pow(2, 8)); // int(256)
echo pow(-1, 20), PHP_EOL; // 1
echo pow(0, 0), PHP_EOL; // 1
echo pow(10, -1), PHP_EOL; // 0.1
-var_dump(pow(new GMP("3"), new GMP("2"))); // object(GMP)
-
-echo pow(-1, 5.5); // NAN
+echo pow(-1, 5.5), PHP_EOL; // NAN
+?>
+]]>
+ </programlisting>
+ </example>
+ </para>
+ <para>
+ <example>
+ <title>Examples of <function>pow</function> With GMP Extension Object</title>
+ <programlisting role="php" annotations="non-interactive">
+<![CDATA[
+<?php
+var_dump(pow(new GMP("3"), new GMP("2"))); // object(GMP)
?>
]]>
</programlisting>
diff --git a/reference/math/functions/sin.xml b/reference/math/functions/sin.xml
index 21586e613e4e..564105aa6f2e 100644
--- a/reference/math/functions/sin.xml
+++ b/reference/math/functions/sin.xml
@@ -45,11 +45,9 @@
<programlisting role="php">
<![CDATA[
<?php
-
// Precision depends on your precision directive
-echo sin(deg2rad(60)); // 0.866025403 ...
-echo sin(60); // -0.304810621 ...
-
+echo sin(deg2rad(60)), PHP_EOL; // 0.866025403 ...
+echo sin(60), PHP_EOL; // -0.304810621 ...
?>
]]>
</programlisting>
diff --git a/reference/math/functions/sqrt.xml b/reference/math/functions/sqrt.xml
index fae05ed622e8..7f5e48c9414b 100644
--- a/reference/math/functions/sqrt.xml
+++ b/reference/math/functions/sqrt.xml
@@ -46,8 +46,8 @@
<![CDATA[
<?php
// Precision depends on your precision directive
-echo sqrt(9); // 3
-echo sqrt(10); // 3.16227766 ...
+echo sqrt(9), PHP_EOL; // 3
+echo sqrt(10), PHP_EOL; // 3.16227766 ...
?>
]]>
</programlisting>