forked from rustwasm/wasm-bindgen
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically bind float math functions
These tend to have one "pretty obvious" definition in JS anyway, so let's paper over this deficiency in rustc for now by automatically resolving any imports for these functions. Closes rustwasm#28
- Loading branch information
1 parent
9e7a4e7
commit d66bc25
Showing
2 changed files
with
146 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
extern crate test_support; | ||
|
||
#[test] | ||
fn auto_bind_math() { | ||
test_support::project() | ||
.file("src/lib.rs", r#" | ||
#![feature(proc_macro)] | ||
extern crate wasm_bindgen; | ||
use wasm_bindgen::prelude::*; | ||
#[wasm_bindgen] | ||
#[no_mangle] | ||
pub extern fn math(a: f32, b: f64) -> f64 { | ||
b.acos() + | ||
b.asin() + | ||
b.atan() + | ||
b.atan2(b) + | ||
b.cbrt() + | ||
b.cosh() + | ||
b.exp_m1() + | ||
b.ln_1p() + | ||
b.sinh() + | ||
b.tan() + | ||
b.tanh() + | ||
b.hypot(b) + | ||
b.cos() + | ||
b.exp() + | ||
b.exp2() + | ||
b.mul_add(b, b) + | ||
b.log(b) + | ||
b.log10() + | ||
b.log2() + | ||
b.powi(8) + | ||
b.powf(b) + | ||
b.round() + | ||
b.sin() + | ||
(b % (a as f64)) + | ||
((a.cos() + | ||
a.exp() + | ||
a.exp2() + | ||
a.mul_add(a, a) + | ||
a.log(a) + | ||
a.log10() + | ||
a.log2() + | ||
a.powi(8) + | ||
a.powf(a) + | ||
a.round() + | ||
a.sin() + | ||
(a % (b as f32))) as f64) + | ||
(b + 2.0f64.powf(a as f64)) | ||
} | ||
"#) | ||
.file("test.ts", r#" | ||
import { math } from "./out"; | ||
export function test() { | ||
math(1.0, 2.0); | ||
} | ||
"#) | ||
.test(); | ||
} | ||
|