Conversation
There was a problem hiding this comment.
Pull request overview
Implements several Python decimal.Decimal / int-compatibility APIs across Decimo’s numeric types, with accompanying CLI/test coverage and roadmap updates.
Changes:
- Add
BigInt.__float__()andBigInt.bit_count()APIs, plus unit tests. - Add
BigDecimal.scaleb(),BigDecimal.fma(), andBigDecimal.to_string_with_separators(), plus unit tests. - Extend CLI evaluator tests to cover rounding modes; clarify CLI/evaluator precision documentation and update the API roadmap.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/cli/test_evaluator.mojo | Adds evaluator tests verifying rounding-mode behavior at given significant-digit precision. |
| tests/bigint/test_bigint_conversion.mojo | Adds __float__ conversion tests for BigInt. |
| tests/bigint/test_bigint_bitwise.mojo | Adds bit_count() test coverage, including negative and large values. |
| tests/bigdecimal/test_bigdecimal_methods.mojo | Adds tests for scaleb(), fma(), and to_string_with_separators(). |
| src/decimo/bigint/bigint.mojo | Implements __float__() and bit_count() on BigInt (and adds FloatableRaising trait conformance). |
| src/decimo/bigdecimal/bigdecimal.mojo | Implements to_string_with_separators(), fma(), and scaleb() on BigDecimal. |
| src/cli/main.mojo | Clarifies precision option comment as “significant digits”. |
| src/cli/calculator/evaluator.mojo | Improves guard-digits documentation for working precision. |
| docs/plans/api_roadmap.md | Marks newly implemented APIs as completed with brief implementation notes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return Float64(String(self)) | ||
|
|
There was a problem hiding this comment.
__float__ converts via Float64(String(self)), which forces a full base-2^32 → decimal string conversion and then reparses it. For very large BigInt values this is substantially more expensive (time + memory) than converting from the binary words directly; consider a word-based Float64 conversion to avoid the intermediate string if this becomes a hotspot.
| return Float64(String(self)) | |
| var result = 0.0 | |
| # Process words from most significant to least significant. | |
| # Each word contributes 32 bits in base-2^32 representation. | |
| for i in range(len(self.words) - 1, -1, -1): | |
| result = result * 4294967296.0 + Float64(self.words[i]) | |
| # Apply sign (assuming negative values have self.sign < 0). | |
| if self.sign < 0: | |
| result = -result | |
| return result |
| var count = 0 | ||
| for i in range(len(self.words)): | ||
| var w = self.words[i] | ||
| # Kernighan's bit-counting trick | ||
| while w != 0: | ||
| w &= w - 1 | ||
| count += 1 | ||
| return count |
There was a problem hiding this comment.
bit_count() iterates over all self.words. Other methods (e.g., to_string) compute an effective word count that trims most-significant zero words; if BigInt instances can contain such trailing zeros, bit_count() will do unnecessary work. Consider trimming/using an eff_words count before counting bits.
) Implements several Python `decimal.Decimal` / `int`-compatibility APIs across Decimo’s numeric types, with accompanying CLI/test coverage and roadmap updates. **Changes:** - Add `BigInt.__float__()` and `BigInt.bit_count()` APIs, plus unit tests. - Add `BigDecimal.scaleb()`, `BigDecimal.fma()`, and `BigDecimal.to_string_with_separators()`, plus unit tests. - Extend CLI evaluator tests to cover rounding modes; clarify CLI/evaluator precision documentation and update the API roadmap.
Implements several Python
decimal.Decimal/int-compatibility APIs across Decimo’s numeric types, with accompanying CLI/test coverage and roadmap updates.Changes:
BigInt.__float__()andBigInt.bit_count()APIs, plus unit tests.BigDecimal.scaleb(),BigDecimal.fma(), andBigDecimal.to_string_with_separators(), plus unit tests.