chore(core): support for Decimal arithmetic#5991
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughIntroduces new fixed-point decimal types Decimal64, Decimal128, and Decimal256 with arithmetic, scaling, conversion, and formatting APIs; a Knuth-based divider; extensive JMH benchmarks for add/subtract/multiply/divide/round across 128/256-bit types vs BigDecimal; random decimal generators in Rnd; a redesigned NumericException; a small interface addition; and a minor Maven config tweak. Changes
Sequence Diagram(s)sequenceDiagram
participant JMH as JMH Runner
participant BM as *Decimal256DivideBenchmark*
participant D256 as Decimal256
participant KD as DecimalKnuthDivider
JMH->>BM: invoke decimal256Divide()
BM->>D256: copyFrom(dividend)
BM->>D256: divide(divisor, scale, roundingMode)
D256->>KD: instance().ofDividend(...).ofDivisor(...).divide(...)
KD-->>D256: sink(quotient, scale)
D256-->>BM: result
BM-->>JMH: return result
sequenceDiagram
participant App as Calling code
participant NE as NumericException
participant Sink as CharSink
App->>NE: NumericException.instance()
App->>NE: position(0).put("Error: ").put(42).put(' ')
App->>Sink: new StringSink()
NE->>Sink: toSink(sink)
Sink-->>App: "Error: 42 "
Estimated code review effort🎯 5 (Critical) | ⏱️ ~90 minutes ✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
|
Hi, where can I ask questions at the global level? #1565 ? #4504 ? questdb/roadmap#89 ? Or another, or is it ok if i ask here? I believe your thinking might be the same, but wanted to say hi and double check. Q: in the task above called "automatic scale", do you mean What I mean to ask is are you considering math ops between numbers with different scale? I'm thinking that potential disadvantages to scale encoded in each value (vs encoded in column type), at bit lengths from 32 to 256, include
isn't it? But you would know better, pls lemme know. Especially since for money in particular (the origin of the business request i saw, may be missing other use cases), they would likely be ok with scale defined at column level, isnt' it? |
|
Also it was probably considered but double double ie double128 or double160 could be an alternative? Though the encoding scale in value is a drawback. Alternatively could we emit such types of different widths and scale when fixed for a type as bytecode at runtime like we do for JIT? |
…zing divide method
…ter accuracy and overflow handling
…ers for target scale
…curacy and overflow handling; add comprehensive fuzz testing
…reference divisor instead of dividend
…division handling
…erformance and precision
…ved error handling in Decimal classes
…ved error handling in Decimal tests
[PR Coverage check]😍 pass : 1927 / 1934 (99.64%) file detail
|
TODO: