Skip to content

Commit 9b70f14

Browse files
committed
Add ceil to Math
1 parent 2de2a81 commit 9b70f14

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/js.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@ extern {
302302
#[wasm_bindgen(static_method_of = Math)]
303303
pub fn cbrt(x: i32) -> Number;
304304

305+
/// The Math.ceil() function returns the smallest integer greater than
306+
/// or equal to a given number.
307+
///
308+
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil
309+
#[wasm_bindgen(static_method_of = Math)]
310+
pub fn ceil(x: f32) -> Number;
305311
}
306312

307313
// Number.

tests/all/js_globals/Math.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,30 @@ fn cbrt() {
238238
"#)
239239
.test()
240240
}
241+
242+
#[test]
243+
fn ceil() {
244+
project()
245+
.file("src/lib.rs", r#"
246+
#![feature(proc_macro, wasm_custom_section)]
247+
248+
extern crate wasm_bindgen;
249+
use wasm_bindgen::prelude::*;
250+
use wasm_bindgen::js;
251+
252+
#[wasm_bindgen]
253+
pub fn ceil(x: f32) -> js::Number {
254+
js::Math::ceil(x)
255+
}
256+
"#)
257+
.file("test.ts", r#"
258+
import * as assert from "assert";
259+
import * as wasm from "./out";
260+
261+
export function test() {
262+
assert.equal(wasm.ceil(1.1), 2);
263+
assert.equal(wasm.ceil(-1.1), -1);
264+
}
265+
"#)
266+
.test()
267+
}

0 commit comments

Comments
 (0)