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
UD60x18.sol # Unsigned 60.18 fixed-point type
SD1x18.sol # Signed 1.18 (compact)
UD2x18.sol # Unsigned 2.18 (compact)
SD21x18.sol # Signed 21.18 (medium)
UD21x18.sol # Unsigned 21.18 (medium)
sd59x18/ # SD59x18 operations (math, conversions, helpers)
ud60x18/ # UD60x18 operations (math, conversions, helpers)
casting/ # Type casting between formats
test/
unit/ # Unit tests
fuzz/ # Fuzz tests
utils/ # Test utilities
bun run build- Build with Forgebun run test- Run tests (forge test)bun run full-check- Prettier + Solhint + Forge format checkbun run full-write- Auto-fix all formatting issues
After generating or updating code:
- Run
bun run full-checkto verify - If errors, run
bun run 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