Skip to content

Commit 1e3fee8

Browse files
authored
[decimal] Implement exp() for BigDecimal (#74)
1 parent 1e354a1 commit 1e3fee8

File tree

9 files changed

+995
-28
lines changed

9 files changed

+995
-28
lines changed

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
# DeciMojo
1+
# DeciMojo <!-- omit in toc -->
22

33
A comprehensive decimal and integer mathematics library for [Mojo](https://www.modular.com/mojo).
44

55
**[中文·漢字»](https://zhuyuhao.com/decimojo/docs/readme_zht.html)** | **[Repository on GitHub»](https://github.com/forfudan/decimojo)** | **[Changelog](https://zhuyuhao.com/decimojo/docs/changelog.html)**
66

7+
- [Overview](#overview)
8+
- [Installation](#installation)
9+
- [Quick start](#quick-start)
10+
- [Objective](#objective)
11+
- [Nomenclature](#nomenclature)
12+
- [Status](#status)
13+
- [Tests and benches](#tests-and-benches)
14+
- [Citation](#citation)
15+
- [License](#license)
16+
717
## Overview
818

919
DeciMojo provides a comprehensive decimal and integer mathematics library for Mojo, delivering exact calculations for financial modeling, scientific computing, and applications where floating-point approximation errors are unacceptable. Beyond basic arithmetic, the library includes advanced mathematical functions with guaranteed precision.
@@ -168,15 +178,15 @@ The name ultimately emphasizes our mission: bringing precise, reliable decimal c
168178

169179
Rome wasn't built in a day. DeciMojo is currently under active development. For the 128-bit `Decimal` type, it has successfully progressed through the **"make it work"** phase and is now well into the **"make it right"** phase with many optimizations already in place. Bug reports and feature requests are welcome! If you encounter issues, please [file them here](https://github.com/forfudan/decimojo/issues).
170180

171-
### Make it Work ✅ (COMPLETED)
181+
### Make it Work ✅ (COMPLETED) <!-- omit in toc -->
172182

173183
- Core decimal implementation with a robust 128-bit representation (96-bit coefficient + 32-bit flags)
174184
- Comprehensive arithmetic operations (+, -, *, /, %, **) with proper overflow handling
175185
- Type conversions to/from various formats (String, Int, Float64, etc.)
176186
- Proper representation of special values (NaN, Infinity)
177187
- Full suite of comparison operators with correct decimal semantics
178188

179-
### Make it Right 🔄 (MOSTLY COMPLETED)
189+
### Make it Right 🔄 (MOSTLY COMPLETED) <!-- omit in toc -->
180190

181191
- Reorganized codebase with modular structure (decimal, arithmetics, comparison, exponential).
182192
- Edge case handling for all operations (division by zero, zero to negative power).
@@ -186,7 +196,7 @@ Rome wasn't built in a day. DeciMojo is currently under active development. For
186196
- Proper implementation of traits (Absable, Comparable, Floatable, Roundable, etc).
187197
- **BigInt and BigUInt** implementations with complete arithmetic operations, proper division semantics (floor and truncate), and support for arbitrary-precision calculations.
188198

189-
### Make it Fast ⚡ (SIGNIFICANT PROGRESS)
199+
### Make it Fast ⚡ (SIGNIFICANT PROGRESS) <!-- omit in toc -->
190200

191201
DeciMojo delivers exceptional performance compared to Python's `decimal` module while maintaining precise calculations. This performance difference stems from fundamental design choices:
192202

@@ -202,7 +212,7 @@ This architectural difference explains our benchmarking results:
202212

203213
Regular benchmarks against Python's `decimal` module are available in the `bench/` folder, documenting both the performance advantages and the few specific operations where different approaches are needed.
204214

205-
### Future Extensions 🚀 (PLANNED)
215+
### Future Extensions 🚀 (PLANNED) <!-- omit in toc -->
206216

207217
- **BigDecimal**: 🔄 **IN PROGRESS** - Arbitrary-precision decimal type with configurable precision[^arbitrary].
208218
- **BigComplex**: 📝 **PLANNED** - Arbitrary-precision complex number type built on BigDecimal.

benches/bigdecimal/bench.mojo

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ from bench_bigdecimal_subtract import main as bench_sub
33
from bench_bigdecimal_multiply import main as bench_multiply
44
from bench_bigdecimal_divide import main as bench_divide
55
from bench_bigdecimal_sqrt import main as bench_sqrt
6+
from bench_bigdecimal_exp import main as bench_exp
67
from bench_bigdecimal_scale_up_by_power_of_10 import main as bench_scale_up
78

89

@@ -17,6 +18,7 @@ sub: Subtract
1718
mul: Multiply
1819
div: Divide (true divide)
1920
sqrt: Square root
21+
exp: Exponential
2022
all: Run all benchmarks
2123
q: Exit
2224
=========================================
@@ -35,12 +37,15 @@ scaleup: Scale up by power of 10
3537
bench_divide()
3638
elif command == "sqrt":
3739
bench_sqrt()
40+
elif command == "exp":
41+
bench_exp()
3842
elif command == "all":
3943
bench_add()
4044
bench_sub()
4145
bench_multiply()
4246
bench_divide()
4347
bench_sqrt()
48+
bench_exp()
4449
elif command == "q":
4550
return
4651
elif command == "scaleup":

0 commit comments

Comments
 (0)