Skip to content

Conversation

@dkuku
Copy link
Contributor

@dkuku dkuku commented Oct 4, 2025

I took a try on the decimal exponent handling. This is the result:

  • Handle positive exponents (e.g., 1.5e10) by multiplying the coefficient during conversion
  • Add overflow detection with checked_mul to reject values that don't fit in i128
  • Adjust scale to return 0 for positive exponents (since they represent whole numbers)
  • Validate during decoding so conversions can safely unwrap

Tests cover mixed exponent arithmetic and overflow cases.
closes #1123
I implemented it with claude code. The max precision for decimal is 38 according to the docs because internally it is backed by i128.

@dkuku dkuku force-pushed the decimal_exponent_handling branch from 3d99032 to 082effa Compare October 4, 2025 18:34
@dkuku dkuku marked this pull request as draft October 4, 2025 18:40
@dkuku dkuku marked this pull request as ready for review October 4, 2025 18:54
Copy link
Member

@billylanchantin billylanchantin left a comment

Choose a reason for hiding this comment

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

I implemented it with claude code.

Thanks for the clarity! We definitely want developers to let us know when they do this. We should probably write up a policy...

@dkuku dkuku force-pushed the decimal_exponent_handling branch from ead3a33 to 29ef928 Compare October 13, 2025 17:47
@dkuku dkuku marked this pull request as draft October 13, 2025 18:22
@dkuku dkuku force-pushed the decimal_exponent_handling branch from c4080f5 to a53c8b2 Compare October 13, 2025 18:41
@dkuku dkuku force-pushed the decimal_exponent_handling branch from a53c8b2 to 67efdae Compare October 13, 2025 18:42
@dkuku dkuku requested a review from billylanchantin October 13, 2025 18:43
@dkuku dkuku marked this pull request as ready for review October 13, 2025 18:43
Copy link
Member

@billylanchantin billylanchantin left a comment

Choose a reason for hiding this comment

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

Thank you, @dkuku! Great work!

I appreciate you tackling that issue :)

@billylanchantin billylanchantin merged commit 157e068 into elixir-explorer:main Oct 13, 2025
4 checks passed
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.

Decimal exponent is ignored - Decimal.new("2.58e4") is treated as 2

2 participants