Skip to content

Commit 761d722

Browse files
committed
Enable WASM for book.math, and tweak examples
1 parent d816a0f commit 761d722

File tree

14 files changed

+93
-37
lines changed

14 files changed

+93
-37
lines changed

reference/math/book.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- $Revision$ -->
3-
<book xml:id="book.math" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
3+
<book xml:id="book.math" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" annotations="interactive">
44
<?phpdoc extension-membership="core" ?>
55
<title>Mathematical Functions</title>
66
<titleabbrev>Math</titleabbrev>

reference/math/functions/ceil.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
<programlisting role="php">
7474
<![CDATA[
7575
<?php
76-
echo ceil(4.3); // 5
77-
echo ceil(9.999); // 10
78-
echo ceil(-3.14); // -3
76+
echo ceil(4.3), PHP_EOL; // 5
77+
echo ceil(9.999), PHP_EOL; // 10
78+
echo ceil(-3.14), PHP_EOL; // -3
7979
?>
8080
]]>
8181
</programlisting>

reference/math/functions/deg2rad.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<![CDATA[
4949
<?php
5050
51-
echo deg2rad(45); // 0.785398163397
51+
echo deg2rad(45), PHP_EOL; // 0.785398163397
5252
var_dump(deg2rad(45) === M_PI_4); // bool(true)
5353
5454
?>

reference/math/functions/exp.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@
5050
<programlisting role="php">
5151
<![CDATA[
5252
<?php
53-
echo exp(12) . "\n";
53+
echo exp(12), PHP_EOL;
5454
echo exp(5.7);
5555
?>
5656
]]>
5757
</programlisting>
5858
&example.outputs;
5959
<screen>
6060
<![CDATA[
61-
1.6275E+005
62-
298.87
61+
162754.791419
62+
298.86740096706
6363
]]>
6464
</screen>
6565
</example>

reference/math/functions/floor.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@
7171
<programlisting role="php">
7272
<![CDATA[
7373
<?php
74-
echo floor(4.3); // 4
75-
echo floor(9.999); // 9
76-
echo floor(-3.14); // -4
74+
echo floor(4.3), PHP_EOL; // 4
75+
echo floor(9.999), PHP_EOL; // 9
76+
echo floor(-3.14), PHP_EOL; // -4
7777
?>
7878
]]>
7979
</programlisting>

reference/math/functions/fmod.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ $x = 5.7;
6565
$y = 1.3;
6666
$r = fmod($x, $y);
6767
// $r equals 0.5, because 4 * 1.3 + 0.5 = 5.7
68+
69+
var_dump($x, $y, $r);
6870
?>
6971
]]>
7072
</programlisting>

reference/math/functions/hexdec.xml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,21 @@
7676
<programlisting role="php">
7777
<![CDATA[
7878
<?php
79-
var_dump(hexdec("See"));
80-
var_dump(hexdec("ee"));
81-
// both print "int(238)"
82-
79+
var_dump(hexdec("ee")); // prints "int(238)"
80+
var_dump(hexdec("a0")); // prints "int(160)"
81+
?>
82+
]]>
83+
</programlisting>
84+
</example>
85+
</para>
86+
<para>
87+
<example>
88+
<title><function>hexdec</function> with Invalid Characters</title>
89+
<programlisting role="php">
90+
<![CDATA[
91+
<?php
92+
var_dump(hexdec("See")); // print "int(238)"
8393
var_dump(hexdec("that")); // print "int(10)"
84-
var_dump(hexdec("a0")); // print "int(160)"
8594
?>
8695
]]>
8796
</programlisting>

reference/math/functions/intdiv.xml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,10 @@ var_dump(intdiv(3, -2));
6666
var_dump(intdiv(-3, -2));
6767
var_dump(intdiv(PHP_INT_MAX, PHP_INT_MAX));
6868
var_dump(intdiv(PHP_INT_MIN, PHP_INT_MIN));
69-
var_dump(intdiv(PHP_INT_MIN, -1));
70-
var_dump(intdiv(1, 0));
7169
?>
7270
]]>
7371
</programlisting>
72+
&example.outputs;
7473
<screen>
7574
<![CDATA[
7675
int(1)
@@ -79,9 +78,35 @@ int(-1)
7978
int(1)
8079
int(1)
8180
int(1)
81+
]]>
82+
</screen>
83+
</example>
84+
</para>
85+
<para>
86+
<example>
87+
<title><function>intdiv</function> Example With Invalid Divisor</title>
88+
<programlisting role="php">
89+
<![CDATA[
90+
<?php
91+
try {
92+
intdiv(PHP_INT_MIN, -1);
93+
} catch (Error $e) {
94+
echo get_class($e), ': ', $e->getMessage(), PHP_EOL;
95+
}
8296
83-
Fatal error: Uncaught ArithmeticError: Division of PHP_INT_MIN by -1 is not an integer in %s on line 8
84-
Fatal error: Uncaught DivisionByZeroError: Division by zero in %s on line 9
97+
try {
98+
intdiv(1, 0);
99+
} catch (Error $e) {
100+
echo get_class($e), ': ', $e->getMessage(), PHP_EOL;
101+
}
102+
?>
103+
]]>
104+
</programlisting>
105+
&example.outputs;
106+
<screen>
107+
<![CDATA[
108+
ArithmeticError: Division of PHP_INT_MIN by -1 is not an integer
109+
DivisionByZeroError: Division by zero
85110
]]>
86111
</screen>
87112
</example>

reference/math/functions/max.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,30 +127,35 @@
127127
<programlisting role="php">
128128
<![CDATA[
129129
<?php
130-
echo max(2, 3, 1, 6, 7); // 7
131-
echo max(array(2, 4, 5)); // 5
130+
echo max(2, 3, 1, 6, 7), PHP_EOL; // 7
131+
echo max(array(2, 4, 5)), PHP_EOL; // 5
132132
133133
// Here we are comparing -1 < 0, so 'hello' is the highest value
134-
echo max('hello', -1); // hello
134+
echo max('hello', -1), PHP_EOL; // hello
135135
136136
// With multiple arrays of different lengths, max returns the longest
137137
$val = max(array(2, 2, 2), array(1, 1, 1, 1)); // array(1, 1, 1, 1)
138+
var_dump($val);
138139
139140
// Multiple arrays of the same length are compared from left to right
140141
// so in our example: 2 == 2, but 5 > 4
141142
$val = max(array(2, 4, 8), array(2, 5, 1)); // array(2, 5, 1)
143+
var_dump($val);
142144
143145
// If both an array and non-array are given, the array will be returned
144146
// as comparisons treat arrays as greater than any other value
145147
$val = max('string', array(2, 5, 7), 42); // array(2, 5, 7)
148+
var_dump($val);
146149
147150
// If one argument is NULL or a boolean, it will be compared against
148151
// other values using the rule FALSE < TRUE regardless of the other types involved
149152
// In the below example, -10 is treated as TRUE in the comparison
150153
$val = max(-10, FALSE); // -10
154+
var_dump($val);
151155
152156
// 0, on the other hand, is treated as FALSE, so is "lower than" TRUE
153157
$val = max(0, TRUE); // TRUE
158+
var_dump($val);
154159
?>
155160
]]>
156161
</programlisting>

reference/math/functions/min.xml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,32 +127,39 @@
127127
<programlisting role="php">
128128
<![CDATA[
129129
<?php
130-
echo min(2, 3, 1, 6, 7); // 1
131-
echo min(array(2, 4, 5)); // 2
130+
echo min(2, 3, 1, 6, 7), PHP_EOL; // 1
131+
echo min(array(2, 4, 5)), PHP_EOL; // 2
132132
133133
// Here we are comparing -1 < 0, so -1 is the lowest value
134-
echo min('hello', -1); // -1
134+
echo min('hello', -1), PHP_EOL; // -1
135135
136136
// With multiple arrays of different lengths, min returns the shortest
137137
$val = min(array(2, 2, 2), array(1, 1, 1, 1)); // array(2, 2, 2)
138+
var_dump($val);
138139
139140
// Multiple arrays of the same length are compared from left to right
140141
// so in our example: 2 == 2, but 4 < 5
141142
$val = min(array(2, 4, 8), array(2, 5, 1)); // array(2, 4, 8)
143+
var_dump($val);
142144
143145
// If both an array and non-array are given, the array is never returned
144146
// as comparisons treat arrays as greater than any other value
145147
$val = min('string', array(2, 5, 7), 42); // string
148+
var_dump($val);
146149
147150
// If one argument is NULL or a boolean, it will be compared against
148151
// other values using the rules FALSE < TRUE and NULL == FALSE regardless of the
149152
// other types involved
150153
// In the below examples, both -10 and 10 are treated as TRUE in the comparison
151154
$val = min(-10, FALSE, 10); // FALSE
155+
var_dump($val);
156+
152157
$val = min(-10, NULL, 10); // NULL
158+
var_dump($val);
153159
154160
// 0, on the other hand, is treated as FALSE, so is "lower than" TRUE
155161
$val = min(0, TRUE); // 0
162+
var_dump($val);
156163
?>
157164
]]>
158165
</programlisting>

0 commit comments

Comments
 (0)