mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-24 18:43:33 +03:00
Add clz32 to Math
This commit is contained in:
parent
9b70f14a1c
commit
e05b1ae6ba
@ -308,6 +308,13 @@ extern {
|
||||
/// 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;
|
||||
|
||||
/// The Math.clz32() function returns the number of leading zero bits in
|
||||
/// the 32-bit binary representation of a number.
|
||||
///
|
||||
/// 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;
|
||||
}
|
||||
|
||||
// Number.
|
||||
|
@ -265,3 +265,30 @@ fn ceil() {
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clz32() {
|
||||
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 clz32(x: i32) -> js::Number {
|
||||
js::Math::clz32(x)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
assert.equal(wasm.clz32(1), 31);
|
||||
assert.equal(wasm.clz32(1000), 22);
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user