Solidity library for advanced fixed-point math with signed (SD59x18) and unsigned (UD60x18) 18-decimal types.
- Solidity 0.8.30
- Foundry (forge build, forge test, forge fmt)
- Bun for package management
- Prettier, Solhint for formatting/linting
src/
Common.sol # Shared utilities (mulDiv, exp2, log2, pow, sqrt)
SD59x18.sol # Signed 59.18 fixed-point type (entry point)
UD60x18.sol # Unsigned 60.18 fixed-point type (entry point)
SD1x18.sol, UD2x18.sol, SD21x18.sol, UD21x18.sol # Compact/medium types
sd59x18/, ud60x18/ # Core type ops (Casting, Constants, Helpers, Math, ValueType)
sd1x18/, ud2x18/, sd21x18/, ud21x18/ # Compact/medium type dirs
casting/ # Casting from uint40/uint128/uint256
test/
unit/ # Unit tests
fuzz/ # Fuzz tests
utils/ # Assertions and test utilities
just build- Build with Forgejust test- Run tests (forge test)just full-check- Prettier + Solhint + Forge format checkjust full-write- Auto-fix all formatting issues
After generating or updating code:
- Run
just full-checkto verify - If errors, run
just full-writeto auto-fix - Fix remaining issues manually
Install dependencies: bun install or bun install -d <pkg> for dev deps.
- Use user-defined value types (SD59x18, UD60x18) for type safety
- Free functions over library pattern
- Custom errors over require strings
- NatSpec comments on public functions
- Line length: 132 chars
- 4-space tabs
- Bracket spacing enabled
| Type | Signed | Integer Digits | Decimals |
|---|---|---|---|
| SD59x18 | Yes | 59 | 18 |
| UD60x18 | No | 60 | 18 |
| SD1x18 | Yes | 1 | 18 |
| UD2x18 | No | 2 | 18 |
| SD21x18 | Yes | 21 | 18 |
| UD21x18 | No | 21 | 18 |
forge test # Run all tests
forge test --match-test testFoo # Run specific test
forge test --match-contract Exp2 # Run tests in contract
FOUNDRY_PROFILE=ci forge test # CI profile with more fuzz runs