Math: Difference between revisions
Jump to navigation
Jump to search
m (→CMath::sinoid) |
m (→CMath::split) |
||
Line 6: | Line 6: | ||
void CMath::split(float xf, float *xr, int *xi) { | void CMath::split(float xf, float *xr, int *xi) { | ||
if ( | if (xf <= 0.0f) { | ||
*xi = xf - 1; | *xi = xf - 1; | ||
Line 13: | Line 13: | ||
} else { | } else { | ||
*xi = | *xi = xf; | ||
*xr = xf - *xi; | *xr = xf - *xi; | ||
Revision as of 04:08, 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 (xf <= 0.0f) {
*xi = xf - 1;
*xr = xf - *xi;
} else {
*xi = xf;
*xr = xf - *xi;
}
}
CMath::sinoid
double CMath::sinoid(float a1) {
int xi;
float xr;
float v1 = a1 * 0.31830987 - 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;
}