steel-decimal

Crates.iosteel-decimal
lib.rssteel-decimal
version1.0.1
created_at2025-07-08 15:13:04.185144+00
updated_at2025-07-26 11:11:37.256376+00
descriptionHigh-precision decimal arithmetic for Steel programming language
homepage
repositoryhttps://gitlab.com/filipriec/steel-decimal
max_upload_size
id1742983
size273,324
(Filipriec)

documentation

README

Steel Decimal

A Rust library that provides high-precision decimal arithmetic support for the Steel programming language. This crate transforms Steel scripts to use decimal operations and provides function registration utilities for Steel VMs.

Features

  • High-precision decimal arithmetic using rust_decimal crate
  • Automatic script transformation from standard math to decimal operations
  • Comprehensive mathematical functions (basic arithmetic, trigonometry, logarithms)
  • Financial calculations with proper decimal precision
  • Configurable precision control
  • Selective function registration via builder pattern
  • Variable support with validation
  • Thread-safe precision contexts

Quick Start

Add this to your Cargo.toml:

[dependencies]
steel_decimal = "1.0.0"

Supported Operations

Basic Arithmetic

  • Addition: (+ a b)(decimal-add "a" "b")
  • Subtraction: (- a b)(decimal-sub "a" "b")
  • Multiplication: (* a b)(decimal-mul "a" "b")
  • Division: (/ a b)(decimal-div "a" "b")

Advanced Mathematics

  • Power: (^ base exp)(decimal-pow "base" "exp")
  • Square root: (sqrt x)(decimal-sqrt "x")
  • Natural log: (ln x)(decimal-ln "x")
  • Base 10 log: (log10 x)(decimal-log10 "x")
  • Exponential: (exp x)(decimal-exp "x")

Trigonometric Functions

  • (sin x), (cos x), (tan x)

Comparison Operations

  • (> a b), (< a b), (= a b), (>= a b), (<= a b)

Financial Functions

  • Percentage: (decimal-percentage amount rate)
  • Compound interest: (decimal-compound principal rate time)

Precision Control

  • Set precision: (set-precision 4)
  • Get current precision: (get-precision)
  • Clear precision: (clear-precision)

Examples

The crate includes several examples:

cargo run --example basic_usage
cargo run --example arithmetic_only
cargo run --example advanced_math
cargo run --example financial_calculations
cargo run --example precision_control
cargo run --example simple_variables
cargo run --example standalone_engine
cargo run --example comparison_methods

Scientific Notation Support

Steel Decimal supports scientific notation in decimal parsing:

let script = "(+ 1.5e2 2.3e-1)"; // 150 + 0.23 = 150.23
let transformed = steel_decimal.transform(script);

Thread Safety

Precision settings are thread-local, allowing different threads to use different precision contexts safely.

License

This project is licensed under either of

at your option.

Commit count: 0

cargo fmt