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

How can we detect if a number is an integral value? #211

Open
MangelMaxime opened this issue Nov 22, 2024 · 0 comments
Open

How can we detect if a number is an integral value? #211

MangelMaxime opened this issue Nov 22, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@MangelMaxime
Copy link
Contributor

MangelMaxime commented Nov 22, 2024

There is currently a subtle bug in Thoth.Json (since for ever probably), where number with decimal set to 0 like 10.0 or 2120.0 are considered integral value.

This is because in JavaScript the test we use is:

function isIntegral(value) {
    return isFinite(value) && Math.floor(value) === value;
}

// Returns
isIntegral(10.0) // ❌
isIntegral(2120.0) // ❌
isIntegral(10.1) // ✅

Case marked with ❌ are incorrect because they return true instead of false.

This means that 10.0 is consider a valid number for int16, etc.

This bug is not present in Thoth.Json.Newtonsoft, neither in Thoth.Json.Python.

@MangelMaxime MangelMaxime added the bug Something isn't working label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant