math_library/lib.rs
1///Adds two 32-bit float numbers and returns the result as a 32-bit float
2pub fn add(a: f32, b: f32) -> f32 { // this is how you do a functionin rust btw
3 a+b
4}
5
6///Subtracts two 32-bit float numbers and returns the result as a 32-bit float
7pub fn sub(a: f32, b: f32) -> f32 {
8 a-b
9}
10
11///Multiplies two 32-bit float numbers and returns the result as a 32-bit float
12pub fn mult(a: f32, b: f32) -> f32 {
13 a*b
14}
15
16///Divides two 32-bit float numbers and returns the result as a 32-bit float
17pub fn div(a: f32, b: f32) -> f32 {
18 a/b
19}
20
21///Raises a 32-bit float number to the power of an unsigned 32-bit integer and returns the result as a 32-bit float
22pub fn pow(a: f32, b: u32) -> f32 {
23 let _i: i32 = 0;
24 let mut result: f32 = 1.0;
25
26 for _i in 1..=b {
27 result *= a;
28 }
29
30 result
31}
32
33///Calculates the factorial of an unsigned 32-bit integer and returns the result as an unsigned 32-bit integer
34pub fn fact(a: u32) -> u32 {
35 if a == 0 {
36 return 1;
37 }
38 let mut result = 1;
39 for a in 1..=a {
40 result *= a;
41 }
42 result
43}
44
45///Calculates the remainder of the division of two 32-bit float numbers and returns the result as a 32-bit float
46pub fn rem(a: f32, b: f32) -> f32 {
47 a % b
48}