July 22nd, 2024

What's the Point? BigDecimal in review

The article reviews BigDecimal's implementation in ClojureCLR, focusing on the General Decimal Arithmetic Specification, its complexities, rounding modes, and precision management in arithmetic operations, particularly addition.

Read original articleLink Icon
What's the Point? BigDecimal in review

The article discusses the implementation of BigDecimal in ClojureCLR, focusing on the General Decimal Arithmetic Specification (GDAS) and its complexities. The author reflects on their experiences with the BigDecimal code, particularly when addressing a bug. The GDAS, a lengthy and dense document, outlines the abstract model for finite numbers defined by three parameters: sign, coefficient, and exponent. The numerical value is calculated using the formula value = (-1)^sign * coefficient * 10^exponent. The author emphasizes the importance of understanding multiple representations of numerically equal values, such as 1 and 1.00, which differ in precision.

The article also covers conversion algorithms between abstract representations and strings, as well as the context object in GDAS that allows for controlling precision and rounding in arithmetic operations. The author explains the five rounding modes defined in GDAS and how they affect calculations. Additionally, the article provides insights into basic arithmetic operations, particularly addition, and how precision and rounding are applied. The author illustrates the addition process with examples, demonstrating how coefficients are aligned based on exponents. The discussion includes the implementation of a context type and the structure of the BigDecimal class, highlighting the need for precision management in arithmetic operations. Overall, the article serves as a technical review of BigDecimal's implementation and its adherence to the GDAS.

Related

A brief introduction to interval arithmetic

A brief introduction to interval arithmetic

Interval arithmetic deals with uncertainties by using intervals instead of exact numbers. It offers accuracy in calculations but faces challenges like complexities and overestimation. Despite evolving, it finds applications in diverse fields.

Y292B Bug

Y292B Bug

The Y292B bug is a potential timekeeping issue in Unix systems due to a rollover in the year 292,277,026,596. Solutions involve using dynamic languages or GNU Multiple Precision Arithmetic Library in C, emphasizing the need for kernel-level fixes.

Q Numbers

Q Numbers

Tim Bray's ongoing fragment delves into Quamina's numeric representation and finite automata intersection. It addresses efficient event pattern matching, normalizing numbers for consistent comparison, and potential precision improvements. Introduced "Q numbers" aim for accurate matching despite performance considerations.

Bignum Arithmetic by AWS

Bignum Arithmetic by AWS

The s2n-bignum project on GitHub provides optimized integer arithmetic routines for cryptography. It includes assembly code for speed and HOL-Light proofs for verification, supporting various languages and emphasizing security and performance.

The algebra (and calculus) of algebraic data types

The algebra (and calculus) of algebraic data types

The relationship between algebraic data types (ADTs) and mathematical algebra is explored, emphasizing similarities in operations. Examples like Choice and binary trees illustrate how algebraic rules apply to ADTs, despite challenges with structures like Nat. Poking holes in data structures is introduced as a way to understand calculus on data types.

Link Icon 0 comments