trig
Trigonometric Functions
All angles are in radians.
Standard Functions
High precision using Taylor series expansion:
sin,cos,tan- Basic trig functionsasin,acos,atan- Inverse functions
Fast Functions
Lower precision using lookup tables (~15x faster):
sin_fast,cos_fast,tan_fastasin_fast,acos_fast,atan_fast
Gas Costs (f128)
| Function | Standard | Fast |
|---|---|---|
| sin/cos | ~2.8M | ~180k |
| tan | ~2.9M | ~360k |
| asin/acos/atan | ~340k | ~330k |
When to Use Fast Variants
Use _fast functions for:
- Games and graphics
- UI animations
- Approximate calculations
Use standard functions for:
- Financial calculations
- Scientific computing
- When precision is critical
Fully qualified path: cairo_fp::f128::math::trig
Constants
| PI_u128 | π (pi) as a fixed-point constant. |
| HALF_PI_u128 | π/2 (half pi) as a fixed-point constant. |
Free functions
| acos | Calculates the arc cosine (inverse cosine)…. |
| acos_fast | Fast arc cosine using lookup table. |
| asin | Calculates the arc sine (inverse sine)…. |
| asin_fast | Fast arc sine using lookup table. |
| atan | Calculates the arc tangent (inverse tangent)…. |
| atan_fast | Fast arc tangent using lookup table. |
| cos | Calculates the cosine of an angle…. |
| cos_fast | Fast cosine using lookup table. |
| sin | Calculates the sine of an angle. Uses Taylor series for high precision…. |
| sin_fast | Fast sine using lookup table. |
| tan | Calculates the tangent of an angle…. |
| tan_fast | Fast tangent using lookup table. |
| _sin_loop | — |