Runtime size is kept below the contract-size limit.
Web3 Lab / Trigonometry Master
Solidity trigonometry, measured against real EVM constraints.
An experimental trigonometry library and benchmark framework for Ethereum-style execution environments—evaluated across gas, precision, bytecode, and Diamond deployment paths.
sin(π/4)
Diamond path
Framework
What Trigonometry Master is
Trigonometry Master is an experimental Solidity trigonometry library, feasibility framework, and Diamond-compatible production-path demonstrator. It studies how binary128-style arithmetic, special-value handling, deployment structure, and gas behavior interact on the EVM without overstating production readiness.
Scope
What it supports
The project combines trigonometric operations with deliberately explicit execution and characterization paths.
sin, cos, tan, cot
asin, acos, atan
ABDK binary128-backed TrigMath facade
Diamond-compatible deployment path
Direct harness, facet, and production-path benchmarks
Raw binary128 edge-case characterization
ULP reporting and bytecode-size guardrails
Measured results
Benchmark highlights
Recorded local Hardhat receipt measurements and size figures. They describe this project configuration, not universal mainnet guarantees.
| Benchmark | Result | Configuration |
|---|---|---|
| sin at π/4 | 43,473 gas | Diamond-routed local Hardhat receipt |
| cos at π/4 | 42,504 gas | Diamond-routed local Hardhat receipt |
| tan at π/4 | 54,827 gas | Diamond-routed local Hardhat receipt |
| cot at π/4 | 54,831 gas | Diamond-routed local Hardhat receipt |
| TrigonometryFacet runtime size | 18,333 bytes | 6,243 bytes of EIP-170 headroom |
| TrigonometryFacet deployment | 4,013,373 gas | Local deployment receipt |
| Default test suite | 40 passing | Current project suite |
Bytecode budget guardrails are part of the suite.
Recorded local installation receipt.
Evidence
Engineering quality and reproducibility
- Explicit policy for NaN, infinity, domain boundaries, and poles
- Signed-zero, subnormal, large finite-value, and raw binary128 edge-case coverage
- Diamond selector, loupe, access-control, and integration tests
- High-resolution sin/cos characterization with ULP reporting
- Bytecode budget tests and production Diamond gas benchmarks
- Deployment script and direct-vs-Diamond trade-off documentation
What this is / what this is not
What this is
- Solidity trigonometry and benchmarking framework
- Web3 numerical-engineering case study
- EVM gas and bytecode feasibility exploration
- Diamond deployment-path demonstrator
What this is not
- An audited production financial-math library
- Proof that all trigonometric workloads are economical on mainnet
- A fully binary128 correctly-rounded trigonometric implementation
- An arbitrary-large-angle Payne–Hanek reducer
Applications
Where it is useful
Feasibility decisions
Web3 teams evaluating whether math-heavy smart-contract work is practical within bounded execution paths.
Deployment trade-offs
Solidity teams comparing direct execution with Diamond routing and deployment overhead.
Numerical research
Research prototypes for EVM numerical computation and bounded on-chain trigonometric utility experiments.
Optimization studies
Gas and bytecode investigations for contracts with specialized mathematical behavior.
Constraints
Feasibility and limitations
- Finite direct-angle inputs are supported for |x| ≤ 2^32.
- sin and cos use finite Taylor polynomials; they are not binary128-accurate across the full binary128 domain.
- Current high-resolution characterization records maximum absolute error of approximately 2.0364e-14 for sine and 3.8881e-13 for cosine.
- The published gas figures are local Hardhat results, not universal mainnet guarantees.
- Arbitrary binary128 angle reduction is intentionally out of scope; it would need multiprecision Payne–Hanek-style reduction.
- Diamond routing adds selector, delegatecall, deployment, and operational complexity.
Trigonometry Master
Explore the implementation, benchmark methodology, deployment path, and documented limits in the public repository.
View on GitHub
Armoni FlowContact