calculator_functions/
lib.rs1pub mod calculator_functions{
2 pub mod basic_functions{
3 pub fn add(x:i32,y:i32) -> i32{
4 x + y
5 }
6
7 pub fn subtract(x:i32,y:i32) -> i32{
8 x - y
9 }
10
11 pub fn multiply(x:i32,y:i32) -> i32{
12 x * y
13 }
14
15 pub fn divide(x:i32,y:i32) -> i32{
16 x / y
17 }
18
19 }
20
21 pub mod power_functions{
22 pub fn square(x:i32) -> i32{
23 x * x
24 }
25
26 pub fn cube(x:i32) -> i32{
27 x * x * x
28 }
29
30 pub fn power(x:i32,power:i32) -> i32{
31 let mut rs = 1;
32 let mut i = 1;
33 while i <= power {
34 rs = rs * x;
35 i = i + 1;
36 }
37 rs
38 }
39 }
40
41}