summaryrefslogtreecommitdiff
path: root/projects/12/Math.jack
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2022-08-16 11:54:23 +0800
committerFrederick Yin <fkfd@fkfd.me>2022-08-16 11:54:23 +0800
commit9542deeb483a00b6fabed7574720926ce97d7511 (patch)
tree0f2c1f72c03dd4693fd59df67544d2a4dddc5494 /projects/12/Math.jack
parent9c0cb1d1c32724fc95ac9548e4f8d873d3adaccc (diff)
Projects, 01-06 completed
Diffstat (limited to 'projects/12/Math.jack')
-rw-r--r--projects/12/Math.jack47
1 files changed, 47 insertions, 0 deletions
diff --git a/projects/12/Math.jack b/projects/12/Math.jack
new file mode 100644
index 0000000..a57f023
--- /dev/null
+++ b/projects/12/Math.jack
@@ -0,0 +1,47 @@
+// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: projects/12/Math.jack
+
+/**
+ * A library of commonly used mathematical functions.
+ * Note: Jack compilers implement multiplication and division using OS method calls.
+ */
+class Math {
+
+ /** Initializes the library. */
+ function void init() {
+ }
+
+ /** Returns the absolute value of x. */
+ function int abs(int x) {
+ }
+
+ /** Returns the product of x and y.
+ * When a Jack compiler detects the multiplication operator '*' in the
+ * program's code, it handles it by invoking this method. In other words,
+ * the Jack expressions x*y and multiply(x,y) return the same value.
+ */
+ function int multiply(int x, int y) {
+ }
+
+ /** Returns the integer part of x/y.
+ * When a Jack compiler detects the multiplication operator '/' in the
+ * program's code, it handles it by invoking this method. In other words,
+ * the Jack expressions x/y and divide(x,y) return the same value.
+ */
+ function int divide(int x, int y) {
+ }
+
+ /** Returns the integer part of the square root of x. */
+ function int sqrt(int x) {
+ }
+
+ /** Returns the greater number. */
+ function int max(int a, int b) {
+ }
+
+ /** Returns the smaller number. */
+ function int min(int a, int b) {
+ }
+}