Skip to content

Commit ddb4f9e

Browse files
authored
fixes #822 (#1017)
1 parent aef4e9c commit ddb4f9e

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

xml/chapter2/section5/subsection1.xml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,54 @@ function install_complex_package() {
994994
arithmetic package. This operation should work for ordinary numbers,
995995
rational numbers, and complex numbers.
996996
<LABEL NAME="ex:=zero?"/>
997+
<SOLUTION>
998+
<SNIPPET EVAL="no">
999+
<JAVASCRIPT>
1000+
// provided by GitHub user clean99
1001+
1002+
function is_equal_to_zero(x) {
1003+
return apply_generic("is_equal", list(x));
1004+
}
1005+
1006+
function install_javascript_number_package() {
1007+
// ...
1008+
1009+
put("is_equal_to_zero", "javascript_number",
1010+
x => x === 0);
1011+
1012+
// ...
1013+
}
1014+
1015+
function install_rational_package() {
1016+
// ...
1017+
1018+
function is_equal_to_zero(x) {
1019+
return numer(x) === 0;
1020+
}
1021+
1022+
put("is_equal_to_zero", "rational",
1023+
is_equal_to_zero);
1024+
1025+
// ...
1026+
}
1027+
1028+
function install_complex_package() {
1029+
// ...
1030+
1031+
function is_equal_to_zero(z) {
1032+
return real_part(z) === 0
1033+
? imag_part(z) === 0
1034+
: false;
1035+
}
1036+
1037+
put("is_equal_to_zero", "complex",
1038+
is_equal_to_zero);
1039+
1040+
//...
1041+
}
1042+
</JAVASCRIPT>
1043+
</SNIPPET>
1044+
</SOLUTION>
9971045
</EXERCISE>
9981046

9991047
<INDEX>generic arithmetic operations<CLOSE/></INDEX>

0 commit comments

Comments
 (0)