mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-01 07:35:02 +03:00
LibM: Add trigonometric approximations and misc mathematical functions
This commit is contained in:
parent
0db2f3cbe6
commit
b7d1eee047
Notes:
sideshowbarker
2024-07-19 13:34:07 +09:00
Author: https://github.com/faissaloo Commit: https://github.com/SerenityOS/serenity/commit/b7d1eee0476 Pull-request: https://github.com/SerenityOS/serenity/pull/234 Reviewed-by: https://github.com/awesomekling
@ -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)
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user