Skip to content

Commit

Permalink
fixes #822 (#1017)
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-henz authored Jul 7, 2024
1 parent aef4e9c commit ddb4f9e
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions xml/chapter2/section5/subsection1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,54 @@ function install_complex_package() {
arithmetic package. This operation should work for ordinary numbers,
rational numbers, and complex numbers.
<LABEL NAME="ex:=zero?"/>
<SOLUTION>
<SNIPPET EVAL="no">
<JAVASCRIPT>
// provided by GitHub user clean99

function is_equal_to_zero(x) {
return apply_generic("is_equal", list(x));
}

function install_javascript_number_package() {
// ...

put("is_equal_to_zero", "javascript_number",
x => x === 0);

// ...
}

function install_rational_package() {
// ...

function is_equal_to_zero(x) {
return numer(x) === 0;
}

put("is_equal_to_zero", "rational",
is_equal_to_zero);

// ...
}

function install_complex_package() {
// ...

function is_equal_to_zero(z) {
return real_part(z) === 0
? imag_part(z) === 0
: false;
}

put("is_equal_to_zero", "complex",
is_equal_to_zero);

//...
}
</JAVASCRIPT>
</SNIPPET>
</SOLUTION>
</EXERCISE>

<INDEX>generic arithmetic operations<CLOSE/></INDEX>
Expand Down

0 comments on commit ddb4f9e

Please sign in to comment.