mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-11-28 23:14:12 +03:00
Merge pull request #331 from gaurikholkar/math-bindings
binding for Math.floor
This commit is contained in:
commit
4b2726d796
@ -360,6 +360,13 @@ extern {
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn clz32(x: i32) -> Number;
|
||||
|
||||
/// The Math.floor() function returns the largest integer less than or
|
||||
/// equal to a given number.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn floor(x: f32) -> Number;
|
||||
}
|
||||
|
||||
// Number.
|
||||
|
@ -292,3 +292,30 @@ fn clz32() {
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn floor() {
|
||||
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 floor(x: f32) -> js::Number {
|
||||
js::Math::floor(x)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
assert.equal(wasm.floor(5.95), 5);
|
||||
assert.equal(wasm.floor(-5.05), -6);
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user