Skip to content

Conversation

@forfudan
Copy link
Owner

This PR re-writes the Decimal constructor from floating-point value by adding a new static method from_float(). It also adds tests and benches.

  • Purpose: Converts a Float64 (double-precision floating-point) value into a Decimal object, enabling precise decimal arithmetic.
  • IEEE 754: Leverages IEEE 754 standard for floating-point representation, using bit manipulation for efficient exponent extraction.
  • Special Value Handling: Explicitly checks for and handles special floating-point values like zero, denormalized numbers, positive/negative infinity, and NaN (Not a Number).
  • Decimal Exponent Approximation: Approximates the decimal exponent from the binary exponent using the mathematical relationship log10(2^exp) = exp * log10(2).
  • Coefficient Extraction: Extracts the integer coefficient representing the significant digits of the Float64.
  • Range Limiting: Ensures that the calculated scale remains within the valid range (0 to Decimal.MAX_SCALE) to prevent errors.

@forfudan forfudan merged commit 409ef50 into main Mar 12, 2025
1 check passed
@forfudan forfudan deleted the float branch March 12, 2025 13:56
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