Skip to content

Commit

Permalink
feat(math): add support for some math functions (txpipe#483)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewWestberg authored Aug 1, 2024
1 parent 3dbd582 commit 2c69435
Show file tree
Hide file tree
Showing 9 changed files with 201,959 additions and 31 deletions.
56 changes: 31 additions & 25 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Based on https://github.com/actions-rs/meta/blob/master/recipes/quickstart.md

on:
push: {}
push: { }

name: Validate

Expand All @@ -11,8 +11,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macOS-latest]
rust: [stable]
os: [ windows-latest, ubuntu-latest, macOS-latest ]
rust: [ stable ]

runs-on: ${{ matrix.os }}

Expand All @@ -21,16 +21,17 @@ jobs:
uses: actions/checkout@v2

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@stable
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true

- name: Run cargo check Windows
if: matrix.os == 'windows-latest'
run: cargo check --no-default-features --features num

- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: check
if: matrix.os != 'windows-latest'
run: cargo check

test:
name: Test Suite
Expand All @@ -40,16 +41,27 @@ jobs:
uses: actions/checkout@v2

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@stable
with:
profile: minimal
toolchain: stable
override: true

- name: Run cargo test
uses: actions-rs/cargo@v1
run: cargo test

test-windows:
name: Test Suite Windows
runs-on: windows-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
with:
command: test
toolchain: stable

- name: Run cargo test
run: cargo test --no-default-features --features num

lints:
name: Lints
Expand All @@ -59,21 +71,15 @@ jobs:
uses: actions/checkout@v2

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@stable
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt, clippy

- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
run: cargo fmt --all -- --check

- name: Run cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
run: |
cargo clippy -- -D warnings
cargo clippy --no-default-features --features num -- -D warnings
12 changes: 11 additions & 1 deletion pallas-math/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,19 @@ license = "Apache-2.0"
readme = "README.md"
authors = ["Andrew Westberg <[email protected]>"]

[features]
default = ["gmp"]
gmp = ["dep:gmp-mpfr-sys"]
num = ["dep:num-bigint", "dep:num-integer", "dep:num-traits"]

[dependencies]
# rug = "1.24.1"
gmp-mpfr-sys = { version = "1.6.4", features = ["mpc"], default-features = false, optional = true }
once_cell = "1.19.0"
num-bigint = { version = "0.4.6", optional = true }
num-integer = { version = "0.1.46", optional = true }
num-traits = { version = "0.2.19", optional = true }
regex = "1.10.5"
thiserror = "1.0.61"

[dev-dependencies]
quickcheck = "1.0"
Expand Down
13 changes: 13 additions & 0 deletions pallas-math/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
pub mod math;

// Ensure only one of `gmp` or `num` is enabled, not both.
#[cfg(all(feature = "gmp", feature = "num"))]
compile_error!("Features `gmp` and `num` are mutually exclusive.");

#[cfg(all(not(feature = "gmp"), not(feature = "num")))]
compile_error!("One of the features `gmp` or `num` must be enabled.");

#[cfg(feature = "gmp")]
pub mod math_gmp;

#[cfg(feature = "num")]
pub mod math_num;
Loading

0 comments on commit 2c69435

Please sign in to comment.