Math: Difference between revisions
Jump to navigation
Jump to search
m (→CMath::sinoid) |
(Restructuring) |
||
Line 1: | Line 1: | ||
== CMath::split == | == CMath == | ||
=== CMath::split === | |||
Given an input of <tt>float xf</tt>, assign the integer part to <tt>int xi</tt>, and the fractional (radix) part to <tt>float xr</tt>. | Given an input of <tt>float xf</tt>, assign the integer part to <tt>int xi</tt>, and the fractional (radix) part to <tt>float xr</tt>. | ||
Line 21: | Line 23: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== CMath::sinoid == | === CMath::sinoid === | ||
Approximates sine for the given input <tt>float a1</tt>. This function is typically inlined. | Approximates sine for the given input <tt>float a1</tt>. This function is typically inlined. | ||
Line 46: | Line 48: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== CMath::cosoid == | === CMath::cosoid === | ||
Approximates cosine for the given input <tt>float a1</tt>. This function is typically inlined. | Approximates cosine for the given input <tt>float a1</tt>. This function is typically inlined. |
Revision as of 01:43, 2 May 2017
CMath
CMath::split
Given an input of float xf, assign the integer part to int xi, and the fractional (radix) part to float xr.
void CMath::split(float xf, float *xr, int *xi) {
if (xf <= 0.0f) {
*xi = xf - 1;
*xr = xf - *xi;
} else {
*xi = xf;
*xr = xf - *xi;
}
}
CMath::sinoid
Approximates sine for the given input float a1. This function is typically inlined.
double CMath::sinoid(float a1) {
int xi;
float xr;
float v1 = (a1 * M_1_PI) - 0.5;
CMath::split(v1, &xr, &xi);
double result = 1.0 - xr * ((6.0 - 4.0 * xr) * xr);
if (xi & 1) {
result = -result;
}
return result;
}
CMath::cosoid
Approximates cosine for the given input float a1. This function is typically inlined.
double CMath::cosoid(float a1) {
int xi;
float xr;
float v1 = a1 * M_1_PI;
CMath::split(v1, &xr, &xi);
double result = 1.0 - xr * ((6.0 - 4.0 * xr) * xr);
if (xi & 1) {
result = -result;
}
return result;
}