From 9d76bea763732dee0358feaeae46840cb75093be Mon Sep 17 00:00:00 2001 From: Ethan Thoma Date: Sat, 21 Dec 2024 14:09:12 -0800 Subject: Add `sample` function to List module, add `log` and `exp` functions to Float module (#772) --- src/gleam_stdlib.mjs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/gleam_stdlib.mjs') diff --git a/src/gleam_stdlib.mjs b/src/gleam_stdlib.mjs index 4f804f7..339963b 100644 --- a/src/gleam_stdlib.mjs +++ b/src/gleam_stdlib.mjs @@ -1010,3 +1010,16 @@ export function bit_array_starts_with(bits, prefix) { return true; } + +export function log(x) { + // It is checked in Gleam that: + // - The input is strictly positive (x > 0) + // - This ensures that Math.log will never return NaN or -Infinity + // The function can thus safely pass the input to Math.log + // and a valid finite float will always be produced. + return Math.log(x); +} + +export function exp(x) { + return Math.exp(x); +} -- cgit v1.2.3