feat: add BigDecimal type to CVM (bounty #5)#578
Open
aglichandrap wants to merge 1 commit into
Open
Conversation
Implements arbitrary-precision decimal arithmetic for the CVM numeric tower. - CVMBigDecimal.java: wraps java.math.BigDecimal, extends ANumeric - Exact decimal arithmetic (add, sub, multiply, divide) - Type promotion: Decimal op Integer -> Decimal, Decimal op Double -> Double - CAD3 encoding: tag 0x1a + VLQ scale + VLQ byte count + unscaled bytes - Canonical if and only if value has meaningful fractional digits - Decimal.java: type class for CVMBigDecimal (Types.DECIMAL) - Core.java: register 'bigdecimal' (code 260) constructor and 'bigdecimal?' (code 261) predicate - CAD3Encoder.java: decode tag 0x1a for BigDecimal wire format - Juice.java: costNumeric() handles CVMBigDecimal (proportional to unscaled byte length) - RT.java: ensureBigDecimal() conversion utility - Tag.java: BIG_DECIMAL = 0x1a - Symbols.java: BIGDECIMAL, BIGDECIMAL_Q Fixes Convex-Dev#5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements arbitrary-precision decimal arithmetic for the CVM numeric tower, fulfilling bounty #5.
Changes
CVMBigDecimal.java: Wraps
java.math.BigDecimal, extendsANumericDecimal op Integer → Decimal,Decimal op Double → Double0x1a+ VLQ signed scale + VLQ byte count + unscaled bytesDecimal.java: Type class for
CVMBigDecimalregistered asTypes.DECIMALCore.java: Registers
bigdecimal(code 260) constructor andbigdecimal?(code 261) predicateCAD3Encoder.java: Decodes tag
0x1a→ reads VLQ scale, VLQ byte count, unscaled bytes → constructsCVMBigDecimalJuice.java:
costNumeric()charges proportional to unscaled byte length (same as BigInteger)RT.java:
ensureBigDecimal()conversion from any numeric typeTag.java:
BIG_DECIMAL = 0x1aSymbols.java:
BIGDECIMAL,BIGDECIMAL_QDesign Decisions
bigdecimalconstructor, 261 forbigdecimal?predicateArithmeticException(preserves exactness)Fixes #5