From 5fddcf38685af5ce4777441ed89691f58add8a9d Mon Sep 17 00:00:00 2001 From: Tyler Wilcock Date: Mon, 23 Jul 2018 09:11:03 -0500 Subject: [PATCH] Add Math.hypot binding (#538) * Add Number.isNaN() binding * Add binding for Math.hypot() --- crates/js-sys/src/lib.rs | 6 ++++++ crates/js-sys/tests/wasm/Math.rs | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index 246abc8d..fc1e69c3 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -1154,6 +1154,12 @@ extern "C" { #[wasm_bindgen(static_method_of = Math)] pub fn fround(x: f64) -> f32; + /// The Math.hypot() function returns the square root of the sum of squares of its arguments. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround + #[wasm_bindgen(static_method_of = Math)] + pub fn hypot(x: f64, y: f64) -> f64; + /// The Math.imul() function returns the result of the C-like 32-bit multiplication of the /// two parameters. /// diff --git a/crates/js-sys/tests/wasm/Math.rs b/crates/js-sys/tests/wasm/Math.rs index eb83b79c..8863fa82 100644 --- a/crates/js-sys/tests/wasm/Math.rs +++ b/crates/js-sys/tests/wasm/Math.rs @@ -128,6 +128,14 @@ fn fround() { assert!(Math::fround(-5.05) == -5.050000190734863); } +#[wasm_bindgen_test] +fn hypot() { + assert!(Math::hypot(3., 4.) == 5.); + assert!(Math::hypot(3.9, 5.2) == 6.5); + assert!(Math::hypot(6., 8.) == 10.); + assert!(Math::hypot(7., 24.) == 25.); +} + #[wasm_bindgen_test] fn imul() { assert!(Math::imul(3, 4) == 12);