Skip to content

Conversation

@tompng
Copy link
Member

@tompng tompng commented Oct 28, 2025

BigMath.frexp(BigDecimal(123.456))
#=> [0.123456e0, 3]

BigMath.ldexp(BigDecimal("0.123456e0"), 3)
#=> 0.123456e3

These methods doesn't take a precision. It just construct or deconstruct BigDecimal from/to fraction part and exponent part without precision loss.

frexp stands for fraction + exponent, ldexp stands for load exponent. It's not limited to binary number.
Math.frexp and Math.ldexp calculates with exponent of 2
BigDecimal version of frexp and ldexp will calculate with exponent of 10.

These two method could be considered an public API version of internal-use BigDecimal#_decimal_shift

@mrkn mrkn added this to the v4.0 milestone Dec 10, 2025
@tompng tompng force-pushed the frexp_ldexp branch 2 times, most recently from 03f2959 to b8bda0c Compare December 11, 2025 19:07
Copy link
Member

@mrkn mrkn left a comment

Choose a reason for hiding this comment

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

@tompng Please check the comment.

tompng and others added 2 commits December 14, 2025 13:41
Math.frexp and ldexp calculates with exponent of 2, BigDecimal version of frexp and ldexp calculates with exponent of 10
Co-authored-by: Kenta Murata <[email protected]>
@tompng tompng merged commit 30c6755 into ruby:master Dec 14, 2025
127 of 128 checks passed
ksss added a commit to ksss/rbs that referenced this pull request Dec 17, 2025
ksss added a commit to ksss/rbs that referenced this pull request Dec 17, 2025
@tompng tompng deleted the frexp_ldexp branch December 19, 2025 06:37
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