Skip to content
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

Bug: infinity f64 values becomes null in Javascript side #48

Open
hillin opened this issue Dec 15, 2024 · 1 comment
Open

Bug: infinity f64 values becomes null in Javascript side #48

hillin opened this issue Dec 15, 2024 · 1 comment

Comments

@hillin
Copy link

hillin commented Dec 15, 2024

[dependencies]
tsify-next = { version = "0.5.4" }
serde = { version = "1.0.215", features = ["derive"] }
wasm-bindgen = "0.2.99"
#[derive(serde::Serialize, serde::Deserialize, tsify_next::Tsify)]
#[tsify(from_wasm_abi, into_wasm_abi)]
pub struct TestResult {
    pub value: f64,
}

#[wasm_bindgen]
pub fn test_negative_infinity() -> TestResult {
    TestResult {
        value: -f64::INFINITY,
    }
}

#[wasm_bindgen]
pub fn test_positive_infinity() -> TestResult {
    TestResult {
        value: f64::INFINITY,
    }
}
test_negative_infinity().value  // null, should be -Infinity
test_positive_infinity().value  // null, should be Infinity

I've tried to decorate the TestResult with #[wasm_bindgen] only, it correctly returns -Infinity and Infinity respectively.

@siefkenj
Copy link
Owner

Very strange indeed. I won't have time to look at this for a while, but if you wanted to investigate, a PR would be welcome!

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

No branches or pull requests

2 participants