Skip to content

Commit f0fd648

Browse files
authored
[float][gmp] Implement most of the methods for BigFloat (#191)
1 parent e3141b8 commit f0fd648

File tree

17 files changed

+1333
-84
lines changed

17 files changed

+1333
-84
lines changed

.github/workflows/run_tests.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,31 @@ jobs:
130130
- name: Run tests
131131
run: bash ./tests/test_decimal128.sh
132132

133+
# ── Test: BigFloat ─────────────────────────────────────────────────────────
134+
test-bigfloat:
135+
name: Test BigFloat
136+
runs-on: ubuntu-22.04
137+
timeout-minutes: 30
138+
env:
139+
DEBIAN_FRONTEND: noninteractive
140+
steps:
141+
- uses: actions/checkout@v4
142+
- name: Install pixi
143+
run: curl -fsSL https://pixi.sh/install.sh | sh
144+
- name: Add pixi to PATH
145+
run: |
146+
echo "PIXI_HOME=$HOME/.pixi" >> $GITHUB_ENV
147+
echo "$HOME/.pixi/bin" >> $GITHUB_PATH
148+
- name: pixi install
149+
run: pixi install
150+
- name: Install MPFR
151+
run: sudo apt-get update && sudo apt-get install -y libmpfr-dev
152+
- name: Build packages
153+
run: |
154+
pixi run mojo package src/decimo && cp decimo.mojopkg tests/
155+
- name: Run tests
156+
run: bash ./tests/test_bigfloat.sh
157+
133158
# ── Test: TOML parser ─────────────────────────────────────────────────────
134159
test-toml:
135160
name: Test TOML parser
@@ -197,6 +222,26 @@ jobs:
197222
- name: Build & run Python tests
198223
run: pixi run testpy
199224

225+
# ── Doc generation check ──────────────────────────────────────────────────────
226+
doc-check:
227+
name: Doc generation
228+
runs-on: ubuntu-22.04
229+
timeout-minutes: 10
230+
env:
231+
DEBIAN_FRONTEND: noninteractive
232+
steps:
233+
- uses: actions/checkout@v4
234+
- name: Install pixi
235+
run: curl -fsSL https://pixi.sh/install.sh | sh
236+
- name: Add pixi to PATH
237+
run: |
238+
echo "PIXI_HOME=$HOME/.pixi" >> $GITHUB_ENV
239+
echo "$HOME/.pixi/bin" >> $GITHUB_PATH
240+
- name: pixi install
241+
run: pixi install
242+
- name: Generate docs
243+
run: pixi run doc
244+
200245
# ── Format check ─────────────────────────────────────────────────────────────
201246
format-check:
202247
name: Format check

docs/plans/gmp_integration.md

Lines changed: 364 additions & 19 deletions
Large diffs are not rendered by default.

pixi.toml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ format = """pixi run mojo format ./src \
2626
&&pixi run ruff format ./python"""
2727

2828
# doc
29-
doc = """pixi run mojo doc \
30-
--diagnose-missing-doc-strings --validate-doc-strings src/decimo"""
29+
doc = "pixi run mojo doc --diagnose-missing-doc-strings src/decimo"
3130

3231
# compile the package
3332
p = "clear && pixi run package"
3433
package = """pixi run format \
34+
&& pixi run doc \
3535
&& pixi run package_decimo"""
3636
package_decimo = """pixi run mojo package src/decimo \
3737
&& cp decimo.mojopkg tests/ \
@@ -43,21 +43,25 @@ c = "clear && pixi run clean"
4343
clean = """rm tests/decimo.mojopkg && \
4444
rm benches/decimo.mojopkg"""
4545

46+
# gmp/mpfr wrapper (compile C wrapper — no MPFR needed at build time)
47+
bgmp = "clear && pixi run buildgmp"
48+
buildgmp = "bash src/decimo/gmp/build_gmp_wrapper.sh"
49+
4650
# tests (use the mojo testing tool)
47-
t = "clear && pixi run test"
48-
tdecimo = "clear && pixi run testdecimo"
4951
test = "pixi run package && bash ./tests/test_all.sh"
5052
testdecimo = "pixi run package && bash ./tests/test_decimo.sh"
5153
testtoml = "pixi run package && bash ./tests/test_toml.sh"
54+
# bigfloat (build test binary linking the C wrapper, then run it)
55+
testfloat = "pixi run buildgmp && bash ./tests/test_bigfloat.sh"
56+
# shortcut for tests
57+
t = "clear && pixi run test"
58+
tdecimo = "clear && pixi run testdecimo"
59+
tf = "clear && pixi run testfloat"
5260
ttoml = "clear && pixi run testtoml"
5361

5462
# bench
5563
bench = "pixi run package && bash benches/run_bench.sh"
5664

57-
# gmp/mpfr wrapper (compile C wrapper — no MPFR needed at build time)
58-
bgmp = "clear && pixi run buildgmp"
59-
buildgmp = "bash src/decimo/gmp/build_gmp_wrapper.sh"
60-
6165
# bench with debug assertions enabled
6266
bdec_debug = """clear && pixi run package && cd benches/bigdecimal \
6367
&& pixi run mojo run -I ../ -D ASSERT=all bench.mojo && cd ../.. \

src/decimo/__init__.mojo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ from .decimal128.decimal128 import Decimal128, Dec128
2929
from .bigint.bigint import BigInt, BInt
3030
from .biguint.biguint import BigUInt, BUInt
3131
from .bigdecimal.bigdecimal import BigDecimal, BDec, Decimal
32+
from .bigfloat.bigfloat import BigFloat, BFlt, Float
3233
from .rounding_mode import (
3334
RoundingMode,
3435
ROUND_DOWN,

src/decimo/bigfloat/__init__.mojo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ Modules:
2828
- bigfloat: Core BigFloat struct with constructors, arithmetic, transcendentals
2929
- mpfr_wrapper: Low-level FFI bindings to the MPFR C wrapper
3030
"""
31+
32+
from .bigfloat import BigFloat, BFlt, Float, PRECISION as BIGFLOAT_PRECISION

0 commit comments

Comments
 (0)