Skip to content

Fix handling out of of range exponent in numbers#971

Merged
byroot merged 1 commit intoruby:masterfrom
byroot:large-exponent
Apr 15, 2026
Merged

Fix handling out of of range exponent in numbers#971
byroot merged 1 commit intoruby:masterfrom
byroot:large-exponent

Conversation

@byroot
Copy link
Copy Markdown
Member

@byroot byroot commented Apr 15, 2026

Fix: #970

If the parsed exponent overflows a int32_t passing it to ryu is incorrect.

We could pass it to rb_cstr_to_dbl but then Ruby will emit an annoying warning, instead we can coerce to 0.0 and Inf.

Fix: ruby#970

If the parsed exponent overflows a `int32_t` passing it
to ryu is incorrect.

We could pass it to `rb_cstr_to_dbl` but then Ruby will emit
an annoying warning, instead we can coerce to `0.0` and `Inf`.
@byroot byroot merged commit 20454ba into ruby:master Apr 15, 2026
41 checks passed
@byroot byroot deleted the large-exponent branch April 15, 2026 06:20
}

if (RB_UNLIKELY(exponent > INT32_MAX)) {
return CInfinity;
Copy link
Copy Markdown

@lopopolo lopopolo Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we have to coerce to a signed infinity depending on the negative value?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 1072482

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.

JSON.parse returns incorrect finite values for very large decimal exponents

2 participants