Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #823 #1018

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_to_zero", 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
Loading