diff options
author | Nicklas Sindlev Andersen <nsa200293@live.dk> | 2022-06-07 19:55:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-07 18:55:57 +0100 |
commit | eeceba29e9d27fe1820bf2d806d4699a37a0469c (patch) | |
tree | d14003ab111183644e00f92b48465a379f757a5e /src/gleam_stdlib.mjs | |
parent | 32d63fb1a0d8d46d17ef7077a4eb1e795dd1cc62 (diff) | |
download | gleam_stdlib-eeceba29e9d27fe1820bf2d806d4699a37a0469c.tar.gz gleam_stdlib-eeceba29e9d27fe1820bf2d806d4699a37a0469c.zip |
Fix int.power and float.power functions (#302)
Diffstat (limited to 'src/gleam_stdlib.mjs')
-rw-r--r-- | src/gleam_stdlib.mjs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/gleam_stdlib.mjs b/src/gleam_stdlib.mjs index 97fa491..b4f3d22 100644 --- a/src/gleam_stdlib.mjs +++ b/src/gleam_stdlib.mjs @@ -210,7 +210,7 @@ export function bit_string_to_string(bit_string) { let decoder = new TextDecoder("utf-8", { fatal: true }); return new Ok(decoder.decode(bit_string.buffer)); } catch (_error) { - return new Error(undefined); + return new Error(Nil); } } @@ -239,7 +239,13 @@ export function truncate(float) { } export function power(base, exponent) { - return Math.pow(base, exponent); + // It is checked in Gleam that: + // - The base is non-negative and that the exponent is not fractional. + // - The base is not zero and the exponent is not negative (otherwise + // the result will essentially be divion by zero). + // It can thus be assumed that valid input is passed to the Math.pow + // function and a NaN or Infinity value will not be produced. + return Math.pow(base, exponent) } export function random_uniform() { |