LibM: Add trigonometric approximations and misc mathematical functions

This commit is contained in:
faissaloo 2019-06-16 19:58:45 +01:00 committed by Andreas Kling
parent 0db2f3cbe6
commit b7d1eee047
Notes: sideshowbarker 2024-07-19 13:34:07 +09:00
2 changed files with 34 additions and 9 deletions

View File

@ -2,15 +2,37 @@
#include <LibM/math.h>
extern "C" {
double cos(double)
double trunc(double x)
{
ASSERT_NOT_REACHED();
return (int)x;
}
double sin(double)
double cos(double angle)
{
ASSERT_NOT_REACHED();
return sin(angle + M_PI_2);
}
double ampsin(double angle)
{
double looped_angle = fmod(M_PI + angle, M_TAU);
double looped_angle_squared = looped_angle * looped_angle;
double quadratic_term;
if (looped_angle_squared > 0) {
quadratic_term = -looped_angle_squared;
} else {
quadratic_term = looped_angle_squared;
}
double linear_term = M_PI * looped_angle;
return quadratic_term * linear_term;
}
double sin(double angle)
{
double vertical_scaling = M_PI_2 * M_PI_2;
return ampsin(angle) / vertical_scaling;
}
double pow(double x, double y)
@ -31,9 +53,9 @@ double tanh(double)
ASSERT_NOT_REACHED();
}
double tan(double)
double tan(double angle)
{
ASSERT_NOT_REACHED();
return ampsin(angle) / ampsin(M_PI_2 + angle);
}
double sqrt(double)
@ -56,9 +78,9 @@ double log(double)
ASSERT_NOT_REACHED();
}
double fmod(double, double)
double fmod(double index, double period)
{
ASSERT_NOT_REACHED();
return index - trunc(index / period) * period;
}
double exp(double)

View File

@ -5,6 +5,9 @@
__BEGIN_DECLS
#define HUGE_VAL 1e10000
#define M_PI 3.141592653589793
#define M_PI_2 (M_PI / 2)
#define M_TAU (M_PI * 2)
double acos(double);
float acosf(float);