summaryrefslogtreecommitdiff
path: root/projects/12/MathTest/Math.jack
diff options
context:
space:
mode:
Diffstat (limited to 'projects/12/MathTest/Math.jack')
-rw-r--r--projects/12/MathTest/Math.jack12
1 files changed, 12 insertions, 0 deletions
diff --git a/projects/12/MathTest/Math.jack b/projects/12/MathTest/Math.jack
index 6bac42e..01bce8f 100644
--- a/projects/12/MathTest/Math.jack
+++ b/projects/12/MathTest/Math.jack
@@ -28,6 +28,18 @@ class Math {
return ~(x & twoToThe[i] = 0);
}
+ function int sign(int x) {
+ if (x > 0) {
+ return 1;
+ } else {
+ if (x < 0) {
+ return -1;
+ } else {
+ return 0;
+ }
+ }
+ }
+
/** Returns the absolute value of x. */
function int abs(int x) {
if (x > 0){