-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.mo
55 lines (45 loc) · 1.46 KB
/
project.mo
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
48
49
50
51
52
53
54
55
import Int "mo:base/Int";
import Option "mo:base/Option";
import Calculator "Calculator";
actor bc2305 {
//=============== DAY 1 - THE CALCULATOR ===============\\
// https://github.com/motoko-bootcamp/motoko-starter/tree/main/days/day-1/project
var counter : Float = 0;
public func add(x : Float) : async Float {
counter := Calculator.add(counter, x);
return counter;
};
public func sub(x : Float) : async Float {
counter := Calculator.subtract(counter, x);
return counter;
};
public func mul(x : Float) : async Float {
counter := Calculator.multiply(counter, x);
return counter;
};
public func div(x : Float) : async ?Float {
counter := Option.get(Calculator.divide(counter, x), counter);
return Option.make(counter);
};
// dfx canister call bc2305 reset
// Should set the counter to: 0
public func reset(): async () {
counter := 0;
};
// dfx canister call bc2305 see
// Should give: (5 : nat)
public query func see() : async Float {
return counter;
};
public func power(x : Float) : async Float {
counter := Calculator.power(counter, x);
return counter;
};
public func sqrt() : async Float {
counter := Calculator.sqrt(counter);
return counter;
};
public func floor() : async Int {
return Calculator.floor(counter);
};
};