Skip to content

Commit 5fddcf3

Browse files
twilcoalexcrichton
authored andcommitted
Add Math.hypot binding (#538)
* Add Number.isNaN() binding * Add binding for Math.hypot()
1 parent 5a0f8e7 commit 5fddcf3

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

crates/js-sys/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,12 @@ extern "C" {
11541154
#[wasm_bindgen(static_method_of = Math)]
11551155
pub fn fround(x: f64) -> f32;
11561156

1157+
/// The Math.hypot() function returns the square root of the sum of squares of its arguments.
1158+
///
1159+
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround
1160+
#[wasm_bindgen(static_method_of = Math)]
1161+
pub fn hypot(x: f64, y: f64) -> f64;
1162+
11571163
/// The Math.imul() function returns the result of the C-like 32-bit multiplication of the
11581164
/// two parameters.
11591165
///

crates/js-sys/tests/wasm/Math.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ fn fround() {
128128
assert!(Math::fround(-5.05) == -5.050000190734863);
129129
}
130130

131+
#[wasm_bindgen_test]
132+
fn hypot() {
133+
assert!(Math::hypot(3., 4.) == 5.);
134+
assert!(Math::hypot(3.9, 5.2) == 6.5);
135+
assert!(Math::hypot(6., 8.) == 10.);
136+
assert!(Math::hypot(7., 24.) == 25.);
137+
}
138+
131139
#[wasm_bindgen_test]
132140
fn imul() {
133141
assert!(Math::imul(3, 4) == 12);

0 commit comments

Comments
 (0)