mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-11-24 06:33:33 +03:00
Add ceil to Math
This commit is contained in:
parent
2de2a815d5
commit
9b70f14a1c
@ -302,6 +302,12 @@ extern {
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn cbrt(x: i32) -> Number;
|
||||
|
||||
/// The Math.ceil() function returns the smallest integer greater than
|
||||
/// or equal to a given number.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn ceil(x: f32) -> Number;
|
||||
}
|
||||
|
||||
// Number.
|
||||
|
@ -238,3 +238,30 @@ fn cbrt() {
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ceil() {
|
||||
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 ceil(x: f32) -> js::Number {
|
||||
js::Math::ceil(x)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
assert.equal(wasm.ceil(1.1), 2);
|
||||
assert.equal(wasm.ceil(-1.1), -1);
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user