mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 10:10:52 +00:00
Add cube root (cbrt) to Math
This commit is contained in:
parent
5eb744c7d6
commit
2de2a815d5
@ -294,6 +294,14 @@ extern {
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn atanh(x: i32) -> Number;
|
||||
|
||||
|
||||
/// The Math.cbrt() function returns the cube root of a number, that is
|
||||
/// Math.cbrt(x) = x^3 = the unique y such that y^3 = x
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cbrt
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn cbrt(x: i32) -> Number;
|
||||
|
||||
}
|
||||
|
||||
// Number.
|
||||
|
@ -212,3 +212,29 @@ fn atanh() {
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cbrt() {
|
||||
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 cbrt(x: i32) -> js::Number {
|
||||
js::Math::cbrt(x)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
assert.equal(wasm.cbrt(27), 3);
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user