Skip to content

Add Math.hypot binding #538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/js-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes indeed! @jontro want to file a follow-up PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! #567

#[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.
///
Expand Down
8 changes: 8 additions & 0 deletions crates/js-sys/tests/wasm/Math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down