Keyboard shortcuts

Press or to navigate between chapters

Press ? to show this help

Press Esc to hide this help

trig

Trigonometric Functions

All angles are in radians.

Standard Functions

High precision using Taylor series expansion:

  • sin, cos, tan - Basic trig functions
  • asin, acos, atan - Inverse functions

Fast Functions

Lower precision using lookup tables (~15x faster):

  • sin_fast, cos_fast, tan_fast
  • asin_fast, acos_fast, atan_fast

Gas Costs (f128)

FunctionStandardFast
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

acosCalculates the arc cosine (inverse cosine)….
acos_fastFast arc cosine using lookup table.
asinCalculates the arc sine (inverse sine)….
asin_fastFast arc sine using lookup table.
atanCalculates the arc tangent (inverse tangent)….
atan_fastFast arc tangent using lookup table.
cosCalculates the cosine of an angle….
cos_fastFast cosine using lookup table.
sinCalculates the sine of an angle. Uses Taylor series for high precision….
sin_fastFast sine using lookup table.
tanCalculates the tangent of an angle….
tan_fastFast tangent using lookup table.
_sin_loop