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

Math.frexp and ldexp calculates with exponent of 2, BigDecimal version of frexp and ldexp calculates with exponent of 10
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.

1 participant