Skip to content

Commit 2306500

Browse files
committed
Add acos to Math
1 parent 9633642 commit 2306500

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/js.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,15 @@ extern {
241241
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs
242242
#[wasm_bindgen(static_method_of = Math)]
243243
pub fn abs(number: i32) -> Number;
244+
245+
/// The Math.acos() function returns the arccosine (in radians) of a
246+
/// number, that is ∀x∊[-1;1]
247+
/// Math.acos(x) = arccos(x) = the unique y∊[0;π] such that cos(y)=x
248+
///
249+
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acos
250+
#[wasm_bindgen(static_method_of = Math)]
251+
pub fn acos(adjacent: i32, hypotenuse: i32) -> Number;
252+
244253
}
245254

246255
// Number.

tests/all/js_globals/Math.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,33 @@ fn abs() {
2424
2525
export function test() {
2626
assert.equal(wasm.abs(-32), Math.abs(-32));
27-
assert.equal(wasm.abs(32), 32));
27+
assert.equal(wasm.abs(32), 32);
28+
}
29+
"#)
30+
.test()
31+
}
32+
33+
#[test]
34+
fn acos() {
35+
project()
36+
.file("src/lib.rs", r#"
37+
#![feature(proc_macro, wasm_custom_section)]
38+
39+
extern crate wasm_bindgen;
40+
use wasm_bindgen::prelude::*;
41+
use wasm_bindgen::js;
42+
43+
#[wasm_bindgen]
44+
pub fn acos(adjacent: i32, hypotenuse: i32) -> js::Number {
45+
js::Math::acos(adjacent, hypotenuse)
46+
}
47+
"#)
48+
.file("test.ts", r#"
49+
import * as assert from "assert";
50+
import * as wasm from "./out";
51+
52+
export function test() {
53+
assert.equal(wasm.acos(-1, 1), Math.PI);
2854
}
2955
"#)
3056
.test()

0 commit comments

Comments
 (0)