From d40a314a91896ce55ca3eb21caadcca017f1c85f Mon Sep 17 00:00:00 2001 From: Jonathan Sundqvist Date: Mon, 25 Jun 2018 21:54:24 +0200 Subject: [PATCH] Add acosh to Math --- src/js.rs | 8 ++++++++ tests/all/js_globals/Math.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/js.rs b/src/js.rs index cc39d01e..39c7ca9b 100644 --- a/src/js.rs +++ b/src/js.rs @@ -250,6 +250,14 @@ extern { #[wasm_bindgen(static_method_of = Math)] pub fn acos(adjacent: i32, hypotenuse: i32) -> Number; + /// The Math.acosh() function returns the hyperbolic arc-cosine of a + /// number, that is ∀x ≥ 1 + /// Math.acosh(x) = arcosh(x) = the unique y ≥ 0 such that cosh(y) = x + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh + #[wasm_bindgen(static_method_of = Math)] + pub fn acosh(number: i32) -> Number; + } // Number. diff --git a/tests/all/js_globals/Math.rs b/tests/all/js_globals/Math.rs index beee88bb..b234aaa7 100644 --- a/tests/all/js_globals/Math.rs +++ b/tests/all/js_globals/Math.rs @@ -55,3 +55,30 @@ fn acos() { "#) .test() } + +#[test] +fn acosh() { + project() + .file("src/lib.rs", r#" + #![feature(proc_macro, wasm_custom_section)] + + extern crate wasm_bindgen; + use wasm_bindgen::prelude::*; + use wasm_bindgen::js; + + #[wasm_bindgen] + pub fn acosh(number: i32) -> js::Number { + js::Math::acosh(number) + } + "#) + .file("test.ts", r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + assert.equal(wasm.acosh(1), 0); + assert.equal(wasm.acosh(2), Math.acosh(2)); + } + "#) + .test() +}