Skip to content

Commit 94255c1

Browse files
committed
Add asin to Math
1 parent d40a314 commit 94255c1

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/js.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,14 @@ extern {
258258
#[wasm_bindgen(static_method_of = Math)]
259259
pub fn acosh(number: i32) -> Number;
260260

261+
/// The Math.asin() function returns the arcsine (in radians) of a
262+
/// number, that is ∀x ∊ [-1;1]
263+
/// Math.asin(x) = arcsin(x) = the unique y∊[-π2;π2] such that sin(y) = x
264+
///
265+
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin
266+
#[wasm_bindgen(static_method_of = Math)]
267+
pub fn asin(number: i32) -> Number;
268+
261269
}
262270

263271
// Number.

tests/all/js_globals/Math.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,29 @@ fn acosh() {
8282
"#)
8383
.test()
8484
}
85+
86+
#[test]
87+
fn asin() {
88+
project()
89+
.file("src/lib.rs", r#"
90+
#![feature(proc_macro, wasm_custom_section)]
91+
92+
extern crate wasm_bindgen;
93+
use wasm_bindgen::prelude::*;
94+
use wasm_bindgen::js;
95+
96+
#[wasm_bindgen]
97+
pub fn asin(opposite: i32, hypotenuse: i32) -> js::Number {
98+
js::Math::asin(opposite / hypotenuse)
99+
}
100+
"#)
101+
.file("test.ts", r#"
102+
import * as assert from "assert";
103+
import * as wasm from "./out";
104+
105+
export function test() {
106+
assert.equal(wasm.asin(1, 1), Math.asin(1));
107+
}
108+
"#)
109+
.test()
110+
}

0 commit comments

Comments
 (0)