Skip to content

Implement Math.min() and Math.max() bindings #542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 24, 2018

Conversation

twilco
Copy link
Contributor

@twilco twilco commented Jul 24, 2018

Math.min() and Math.max() for #275.

And while I have your attention... :)

How do we want to do constants? Doesn't look like anyone has made a constant for any binding yet. Tried this, but figured it was too good to be true.

// Math
#[wasm_bindgen]
extern "C" {
    pub type Math;

    const E: f64 = 2.718281828459045;

    /// The Math.abs() function returns the absolute value of a number, that is
    /// Math.abs(x) = |x|
    ///
    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs
    #[wasm_bindgen(static_method_of = Math)]
    pub fn abs(x: f64) -> f64;

Error message is: Static constants in extern blocks cannot have values

let also does not work.

@alexcrichton alexcrichton merged commit cefe168 into rustwasm:master Jul 24, 2018
@alexcrichton
Copy link
Contributor

Awesome, thanks!

For constants... that's a good question! I think though that something like this should in theory work (although it may need some backend work)

#[wasm_bindgen]
extern {
    #[wasm_bindgen(static_method_of = Math)]
    static E: f64;
}

(or something like that)

As I write this I'm quite certain this'll need some backend work! For now it's ok to skip those :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants