Math: Difference between revisions
Jump to navigation
Jump to search
(Initial commit) |
|||
Line 22: | Line 22: | ||
== CMath::sinoid == | == CMath::sinoid == | ||
<syntaxhighlight lang="cpp"> | |||
double CMath::sinoid(float a1) { | |||
float v1 = a1 * 0.31830987 - 0.5; | |||
int xi; | |||
float xr; | |||
CMath::split(v1, &xr, &xi); | |||
float result = 1.0 - xr * ((6.0 - 4.0 * xr) * xr); | |||
if (xi & 1) { | |||
result = -result; | |||
} | |||
return result; | |||
} | |||
</syntaxhighlight> | |||
== CMath::cosoid == | == CMath::cosoid == |
Revision as of 04:00, 12 April 2017
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 (a1 <= 0.0f) {
*xi = xf - 1;
*xr = xf - *xi;
} else {
*xi = a1;
*xr = xf - *xi;
}
}
CMath::sinoid
double CMath::sinoid(float a1) {
float v1 = a1 * 0.31830987 - 0.5;
int xi;
float xr;
CMath::split(v1, &xr, &xi);
float result = 1.0 - xr * ((6.0 - 4.0 * xr) * xr);
if (xi & 1) {
result = -result;
}
return result;
}