Skip to content

Commit e05b1ae

Browse files
committed
Add clz32 to Math
1 parent 9b70f14 commit e05b1ae

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/js.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,13 @@ extern {
308308
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil
309309
#[wasm_bindgen(static_method_of = Math)]
310310
pub fn ceil(x: f32) -> Number;
311+
312+
/// The Math.clz32() function returns the number of leading zero bits in
313+
/// the 32-bit binary representation of a number.
314+
///
315+
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32
316+
#[wasm_bindgen(static_method_of = Math)]
317+
pub fn clz32(x: i32) -> Number;
311318
}
312319

313320
// Number.

tests/all/js_globals/Math.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,30 @@ fn ceil() {
265265
"#)
266266
.test()
267267
}
268+
269+
#[test]
270+
fn clz32() {
271+
project()
272+
.file("src/lib.rs", r#"
273+
#![feature(proc_macro, wasm_custom_section)]
274+
275+
extern crate wasm_bindgen;
276+
use wasm_bindgen::prelude::*;
277+
use wasm_bindgen::js;
278+
279+
#[wasm_bindgen]
280+
pub fn clz32(x: i32) -> js::Number {
281+
js::Math::clz32(x)
282+
}
283+
"#)
284+
.file("test.ts", r#"
285+
import * as assert from "assert";
286+
import * as wasm from "./out";
287+
288+
export function test() {
289+
assert.equal(wasm.clz32(1), 31);
290+
assert.equal(wasm.clz32(1000), 22);
291+
}
292+
"#)
293+
.test()
294+
}

0 commit comments

Comments
 (0)