summaryrefslogtreecommitdiff
path: root/projects/12/Math.jack
blob: a57f0235d09d2d3d6d5041f5ae1944f28ea4bc7f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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) {
    }
}