diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/math.lux | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/stdlib/source/lux/math.lux b/stdlib/source/lux/math.lux index 9369ae44f..e87bb1b1b 100644 --- a/stdlib/source/lux/math.lux +++ b/stdlib/source/lux/math.lux @@ -45,17 +45,13 @@ [exp "invokestatic:java.lang.Math:exp:double"] [log "invokestatic:java.lang.Math:log:double"] - [cbrt "invokestatic:java.lang.Math:cbrt:double"] - [sqrt "invokestatic:java.lang.Math:sqrt:double"] + [root2 "invokestatic:java.lang.Math:sqrt:double"] + [root3 "invokestatic:java.lang.Math:cbrt:double"] [degrees "invokestatic:java.lang.Math:toDegrees:double"] [radians "invokestatic:java.lang.Math:toRadians:double"] ) -(def: #export (square n) - (-> Real Real) - (r.* n n)) - (do-template [<name> <method>] [(def: #export (<name> n) (-> Real Real) @@ -78,6 +74,23 @@ [pow "invokestatic:java.lang.Math:pow:double,double"] ) +(def: #export (log' base input) + (r./ (log base) + (log input))) + +(def: #export (factorial n) + (-> Nat Nat) + (loop [acc +1 + n n] + (if (n.<= +1 n) + acc + (recur (n.* n acc) (n.dec n))))) + +(def: #export (hypotenuse catA catB) + (-> Real Real Real) + (root2 (r.+ (pow 2.0 catA) + (pow 2.0 catB)))) + (def: #export (gcd a b) {#;doc "Greatest Common Divisor."} (-> Nat Nat Nat) |