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 @@ -994,6 +994,54 @@ function install_complex_package() {
994
994
arithmetic package. This operation should work for ordinary numbers,
995
995
rational numbers, and complex numbers.
996
996
<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 >
997
1045
</EXERCISE >
998
1046
999
1047
<INDEX >generic arithmetic operations<CLOSE /></INDEX >
You can’t perform that action at this time.
0 commit comments