| 
 | 1 | +# @brief Calculate e^number  | 
 | 2 | +# @param value the Number  | 
 | 3 | +# =begin  | 
 | 4 | +# (math:exp 1)  # 2.7182...  | 
 | 5 | +# =end  | 
 | 6 | +# @author https://github.com/SuperFola  | 
 | 7 | +(let exp (fun (_x) (builtin__math:exp _x)))  | 
 | 8 | + | 
 | 9 | +# @brief Calculate the logarithm of a number  | 
 | 10 | +# @param value the Number  | 
 | 11 | +# =begin  | 
 | 12 | +# (math:ln 1)  # 0  | 
 | 13 | +# =end  | 
 | 14 | +# @author https://github.com/SuperFola  | 
 | 15 | +(let ln (fun (_x) (builtin__math:ln _x)))  | 
 | 16 | + | 
 | 17 | +# @brief Get the smallest possible integer greater than the number  | 
 | 18 | +# @param value the Number  | 
 | 19 | +# =begin  | 
 | 20 | +# (math:ceil 0.2)  # 1  | 
 | 21 | +# =end  | 
 | 22 | +# @author https://github.com/SuperFola  | 
 | 23 | +(let ceil (fun (_x) (builtin__math:ceil _x)))  | 
 | 24 | + | 
 | 25 | +# @brief Get the smallest possible integer equal to the given number  | 
 | 26 | +# @param value the Number  | 
 | 27 | +# =begin  | 
 | 28 | +# (math:floor 1.7)  # 1  | 
 | 29 | +# =end  | 
 | 30 | +# @author https://github.com/SuperFola  | 
 | 31 | +(let floor (fun (_x) (builtin__math:floor _x)))  | 
 | 32 | + | 
 | 33 | +# @brief Get the smallest possible integer equal to or greater than the given number  | 
 | 34 | +# @param value the Number  | 
 | 35 | +# =begin  | 
 | 36 | +# (math:round 0.2)  # 0  | 
 | 37 | +# (math:round 0.6)  # 1  | 
 | 38 | +# =end  | 
 | 39 | +# @author https://github.com/SuperFola  | 
 | 40 | +(let round (fun (_x) (builtin__math:round _x)))  | 
 | 41 | + | 
 | 42 | +# @brief Check if a Number is NaN  | 
 | 43 | +# @param value the Number  | 
 | 44 | +# =begin  | 
 | 45 | +# (math:NaN? 2)  # false  | 
 | 46 | +# (math:NaN? nan)  # true  | 
 | 47 | +# =end  | 
 | 48 | +# @author https://github.com/SuperFola  | 
 | 49 | +(let NaN? (fun (_x) (builtin__math:NaN? _x)))  | 
 | 50 | + | 
 | 51 | +# @brief Check if a Number if Inf  | 
 | 52 | +# @param value the Number  | 
 | 53 | +# =begin  | 
 | 54 | +# (math:Inf? 1)  # false  | 
 | 55 | +# (math:Inf? nan)  # false  | 
 | 56 | +# =end  | 
 | 57 | +# @author https://github.com/SuperFola  | 
 | 58 | +(let Inf? (fun (_x) (builtin__math:Inf? _x)))  | 
 | 59 | + | 
 | 60 | +# @brief Calculate the cosinus of a number  | 
 | 61 | +# @param value the Number (radians)  | 
 | 62 | +# =begin  | 
 | 63 | +# (math:cos 0)  # 1  | 
 | 64 | +# (math:cos math:pi)  # -1  | 
 | 65 | +# =end  | 
 | 66 | +# @author https://github.com/SuperFola  | 
 | 67 | +(let cos (fun (_x) (builtin__math:cos _x)))  | 
 | 68 | + | 
 | 69 | +# @brief Calculate the sinus of a number  | 
 | 70 | +# @param value the Number (radians)  | 
 | 71 | +# =begin  | 
 | 72 | +# (math:sin 0)  # 0  | 
 | 73 | +# (math:cos (/ math:pi 2))  # 1  | 
 | 74 | +# =end  | 
 | 75 | +# @author https://github.com/SuperFola  | 
 | 76 | +(let sin (fun (_x) (builtin__math:sin _x)))  | 
 | 77 | + | 
 | 78 | +# @brief Calculate the tangent of a number  | 
 | 79 | +# @param value the Number (radians)  | 
 | 80 | +# =begin  | 
 | 81 | +# (math:tan 0)  # 0  | 
 | 82 | +# (math:cos (/ math:pi 4))  # 1  | 
 | 83 | +# =end  | 
 | 84 | +# @author https://github.com/SuperFola  | 
 | 85 | +(let tan (fun (_x) (builtin__math:tan _x)))  | 
 | 86 | + | 
 | 87 | +# @brief Calculate the arc cosinus of a number  | 
 | 88 | +# @param value the Number  | 
 | 89 | +# =begin  | 
 | 90 | +# (math:arccos 1)  # 0  | 
 | 91 | +# =end  | 
 | 92 | +# @author https://github.com/SuperFola  | 
 | 93 | +(let arccos (fun (_x) (builtin__math:arccos _x)))  | 
 | 94 | + | 
 | 95 | +# @brief Calculate the arc sinus of a number  | 
 | 96 | +# @param value the Number  | 
 | 97 | +# =begin  | 
 | 98 | +# (math:arcsin 1)  # 1.570796326794897 (/ math:pi 2)  | 
 | 99 | +# =end  | 
 | 100 | +# @author https://github.com/SuperFola  | 
 | 101 | +(let arcsin (fun (_x) (builtin__math:arcsin _x)))  | 
 | 102 | + | 
 | 103 | +# @brief Calculate the arc tangent of a number  | 
 | 104 | +# @param value the Number  | 
 | 105 | +# =begin  | 
 | 106 | +# (math:arctan 0)  # 0  | 
 | 107 | +# =end  | 
 | 108 | +# @author https://github.com/SuperFola  | 
 | 109 | +(let arctan (fun (_x) (builtin__math:arctan _x)))  | 
 | 110 | + | 
 | 111 | +# @brief Calculate the hyperbolic cosinus of a number  | 
 | 112 | +# @param value the Number  | 
 | 113 | +# @author https://github.com/Gryfenfer97  | 
 | 114 | +(let cosh (fun (_x) (builtin__math:cosh _x)))  | 
 | 115 | + | 
 | 116 | +# @brief Calculate the hyperbolic sinus of a number  | 
 | 117 | +# @param value the Number  | 
 | 118 | +# @author https://github.com/Gryfenfer97  | 
 | 119 | +(let sinh (fun (_x) (builtin__math:sinh _x)))  | 
 | 120 | + | 
 | 121 | +# @brief Calculate the hyperbolic tangent of a number  | 
 | 122 | +# @param value the Number  | 
 | 123 | +# @author https://github.com/Gryfenfer97  | 
 | 124 | +(let tanh (fun (_x) (builtin__math:tanh _x)))  | 
 | 125 | + | 
 | 126 | +# @brief Calculate the hyperbolic arc cosinus of a number  | 
 | 127 | +# @param value the Number  | 
 | 128 | +# @author https://github.com/Gryfenfer97  | 
 | 129 | +(let acosh (fun (_x) (builtin__math:acosh _x)))  | 
 | 130 | + | 
 | 131 | +# @brief Calculate the hyperbolic arc sinus of a number  | 
 | 132 | +# @param value the Number  | 
 | 133 | +# @author https://github.com/Gryfenfer97  | 
 | 134 | +(let asinh (fun (_x) (builtin__math:asinh _x)))  | 
 | 135 | + | 
 | 136 | +# @brief Calculate the hyperbolic arc tangent of a number  | 
 | 137 | +# @param value the Number  | 
 | 138 | +# @author https://github.com/Gryfenfer97  | 
 | 139 | +(let atanh (fun (_x) (builtin__math:atanh _x)))  | 
 | 140 | + | 
 | 141 | +# @brief Pi value (3.14159...)  | 
 | 142 | +# @author https://github.com/SuperFola  | 
 | 143 | +(let pi builtin__math:pi)  | 
 | 144 | + | 
 | 145 | +# @brief E value (2.7182...)  | 
 | 146 | +# @author https://github.com/SuperFola  | 
 | 147 | +(let e builtin__math:e)  | 
 | 148 | + | 
 | 149 | +# @brief Tau, the ratio of the circumference to the radius of a circle, which is equal to 2*pi (6.28318...)  | 
 | 150 | +# @author https://github.com/SuperFola  | 
 | 151 | +(let tau builtin__math:tau)  | 
 | 152 | + | 
 | 153 | +# @brief Float infinite value  | 
 | 154 | +# @author https://github.com/SuperFola  | 
 | 155 | +(let Inf builtin__math:Inf)  | 
 | 156 | + | 
 | 157 | +# @brief Float not-a-number value  | 
 | 158 | +# @author https://github.com/SuperFola  | 
 | 159 | +(let NaN builtin__math:NaN)  | 
 | 160 | + | 
1 | 161 | # @brief Return the absolute value of a number  | 
2 | 162 | # @param _x the number to get the absolute value of  | 
3 | 163 | # @author https://github.com/rstefanic  | 
 | 
39 | 199 | # @param _x the number to pow  | 
40 | 200 | # @param _a the exponent  | 
41 | 201 | # @author https://github.com/SuperFola  | 
42 |  | -(let pow (fun (_x _a) (math:exp (* _a (math:ln _x)))))  | 
 | 202 | +(let pow (fun (_x _a) (exp (* _a (ln _x)))))  | 
43 | 203 | 
 
  | 
44 | 204 | # @brief Get the square root of a number  | 
45 | 205 | # @details Square roots can't be taken for negative numbers for obvious reasons.  | 
46 | 206 | # @param _x the number  | 
47 | 207 | # @author https://github.com/SuperFola  | 
48 |  | -(let sqrt (fun (_x) (math:exp (* 0.5 (math:ln _x)))))  | 
 | 208 | +(let sqrt (fun (_x) (exp (* 0.5 (ln _x)))))  | 
49 | 209 | 
 
  | 
50 | 210 | # @brief Run the fibonacci function on a number  | 
51 | 211 | # @param n the number  | 
 | 
71 | 231 |     (if (or (= 0 (mod n 2)) (= 1 n))  | 
72 | 232 |       false  | 
73 | 233 |       {  | 
74 |  | -        (let k (math:ceil (+ 1 (sqrt n))))  | 
 | 234 | +        (let k (ceil (+ 1 (sqrt n))))  | 
75 | 235 |         (mut i 3)  | 
76 | 236 |         (mut continue true)  | 
77 | 237 | 
 
  | 
 | 
91 | 251 |   (assert (>= n 2) "divs: n must be greater or equal to 2")  | 
92 | 252 |   (mut i 2)  | 
93 | 253 |   (mut divisors [1])  | 
94 |  | -  (let top (math:ceil (/ n 2)))  | 
 | 254 | +  (let top (ceil (/ n 2)))  | 
95 | 255 | 
 
  | 
96 | 256 |   (while (and (<= i top) (!= top n)) {  | 
97 | 257 |     (if (= (mod n i) 0)  | 
 | 
109 | 269 | (let log (fun (x n) {  | 
110 | 270 |   (assert (> x 0) "log: x must be greater than 0")  | 
111 | 271 |   (assert (>= n 1) "log: n must be greater or equal to 1")  | 
112 |  | -  (math:round (/ (math:ln x) (math:ln n))) }))  | 
 | 272 | +  (round (/ (ln x) (ln n))) }))  | 
113 | 273 | 
 
  | 
114 | 274 | # @brief Returns the logarithm base 2 of a number  | 
115 | 275 | # @param x the number  | 
 | 
134 | 294 | # =begin  | 
135 | 295 | # (floordiv 14 6) # Returns 2  | 
136 | 296 | # =end  | 
137 |  | -(let floordiv (fun (a b) (math:floor (/ a b))))  | 
 | 297 | +(let floordiv (fun (a b) (floor (/ a b))))  | 
138 | 298 | 
 
  | 
139 | 299 | # @brief Create a complex number  | 
140 | 300 | # @param real the real part of the complex number  | 
 | 
0 commit comments