Skip to content

Commit 3223a9a

Browse files
committed
Add atan2 to Math
1 parent 7e514b9 commit 3223a9a

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/js.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,13 @@ extern {
279279
#[wasm_bindgen(static_method_of = Math)]
280280
pub fn atan(number: i32) -> Number;
281281

282+
/// The Math.atan2() function returns the arctangent of the quotient of
283+
/// its arguments.
284+
///
285+
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2
286+
#[wasm_bindgen(static_method_of = Math)]
287+
pub fn atan2(y: i32, x: i32) -> Number;
288+
282289
}
283290

284291
// Number.

tests/all/js_globals/Math.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,29 @@ fn atan() {
160160
"#)
161161
.test()
162162
}
163+
164+
#[test]
165+
fn atan2() {
166+
project()
167+
.file("src/lib.rs", r#"
168+
#![feature(proc_macro, wasm_custom_section)]
169+
170+
extern crate wasm_bindgen;
171+
use wasm_bindgen::prelude::*;
172+
use wasm_bindgen::js;
173+
174+
#[wasm_bindgen]
175+
pub fn atan2(x: i32, y: i32) -> js::Number {
176+
js::Math::atan2(x, y)
177+
}
178+
"#)
179+
.file("test.ts", r#"
180+
import * as assert from "assert";
181+
import * as wasm from "./out";
182+
183+
export function test() {
184+
assert.equal(wasm.atan2(1, 2), Math.atan2(1, 2));
185+
}
186+
"#)
187+
.test()
188+
}

0 commit comments

Comments
 (0)