File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -947,6 +947,54 @@ function contents(datum) {
947
947
arithmetic package. This operation should work for ordinary numbers,
948
948
rational numbers, and complex numbers.
949
949
<LABEL NAME =" ex:=zero?" />
950
+ <SOLUTION >
951
+ <SNIPPET EVAL =" no" >
952
+ <JAVASCRIPT >
953
+ // provided by GitHub user clean99
954
+
955
+ function is_equal_to_zero(x) {
956
+ return apply_generic("is_equal", list(x));
957
+ }
958
+
959
+ function install_javascript_number_package() {
960
+ // ...
961
+
962
+ put("is_equal_to_zero", "javascript_number",
963
+ x => x === 0);
964
+
965
+ // ...
966
+ }
967
+
968
+ function install_rational_package() {
969
+ // ...
970
+
971
+ function is_equal_to_zero(x) {
972
+ return numer(x) === 0;
973
+ }
974
+
975
+ put("is_equal_to_zero", "rational",
976
+ is_equal_to_zero);
977
+
978
+ // ...
979
+ }
980
+
981
+ function install_complex_package() {
982
+ // ...
983
+
984
+ function is_equal_to_zero(z) {
985
+ return real_part(z) === 0
986
+ ? imag_part(z) === 0
987
+ : false;
988
+ }
989
+
990
+ put("is_equal_to_zero", "complex",
991
+ is_equal_to_zero);
992
+
993
+ //...
994
+ }
995
+ </JAVASCRIPT >
996
+ </SNIPPET >
997
+ </SOLUTION >
950
998
</EXERCISE >
951
999
952
1000
<INDEX >generic arithmetic operations<CLOSE /></INDEX >
You can’t perform that action at this time.
0 commit comments