Klang C++ 0.7.15
Language Reference (draft)
Loading...
Searching...
No Matches
klang::fast Namespace Reference

Functions

float sin (float x)
 Approximate sine of a finite angle in radians.
 
float cos (float x)
 Approximate cosine of a finite angle in radians.
 
float sinp (unsigned int phase)
 Approximate sine from an unsigned 32-bit phase covering one turn.
 
float cosp (unsigned int phase)
 Approximate cosine from an unsigned 32-bit phase covering one turn.
 

Variables

constexpr float twoPi = float(2.0 * 3.1415926535897932384626433832795)
 

Detailed Description

Fast scalar approximations. Angles use radians unless a p suffix identifies an unsigned 32-bit phase covering one complete turn. Sine uses the retained V2/Farbrausch range reduction and Robin Green odd polynomial. Cosine reuses that polynomial with direct quadrant reduction, avoiding an added pi/2 before the existing modulo step.

Function Documentation

◆ cos()

float klang::fast::cos ( float x)
inline

Definition at line 6320 of file klang.h.

6320 {
6321 x = fast_mod2pi(x);
6322 x = x < pi ? pi / 2.f - x : x - 3.f / 2.f * pi;
6323 return detail::sin(x);
6324 }
float fast_mod2pi(float x)
Definition klang.h:1552
constexpr constant pi
The mathematical constant, pi (and it's inverse).
Definition klang.h:287

References cos(), klang::fast_mod2pi(), and klang::pi.

Referenced by cos().

◆ cosp()

float klang::fast::cosp ( unsigned int phase)
inline

Definition at line 6337 of file klang.h.

6337 {
6338 float x = fast_modp(phase);
6339 x = x < pi ? pi / 2.f - x : x - 3.f / 2.f * pi;
6340 return detail::sin(x);
6341 }
float fast_modp(unsigned int x)
Definition klang.h:1558

References cosp(), klang::fast_modp(), and klang::pi.

Referenced by cosp().

◆ sin()

float klang::fast::sin ( float x)
inline

Definition at line 6310 of file klang.h.

6310 {
6311 x = fast_mod2pi(x);
6312 if (x > 3 / 2.f * pi)
6313 x -= twoPi;
6314 else if (x > pi / 2)
6315 x = pi - x;
6316 return detail::sin(x);
6317 }
constexpr float twoPi
Definition klang.h:6300

References klang::fast_mod2pi(), klang::pi, and twoPi.

◆ sinp()

float klang::fast::sinp ( unsigned int phase)
inline

Definition at line 6327 of file klang.h.

6327 {
6328 float x = fast_modp(phase);
6329 if (x > 3.f / 2.f * pi)
6330 x -= twoPi;
6331 else if (x > pi / 2.f)
6332 x = pi - x;
6333 return detail::sin(x);
6334 }

References klang::fast_modp(), klang::pi, sinp(), and twoPi.

Referenced by klang::Generators::Fast::Sine::process(), and sinp().

Variable Documentation

◆ twoPi

float klang::fast::twoPi = float(2.0 * 3.1415926535897932384626433832795)
constexpr

Definition at line 6300 of file klang.h.

Referenced by sin(), and sinp().