mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 21:40:33 +00:00
LibM: Rewrite trigonometric functions.
This way they seem to actually work as expected ;)
This commit is contained in:
parent
502c54e39a
commit
9fa4e779ff
Notes:
sideshowbarker
2024-07-19 13:33:44 +09:00
Author: https://github.com/bugaevc Commit: https://github.com/SerenityOS/serenity/commit/9fa4e779ff5 Pull-request: https://github.com/SerenityOS/serenity/pull/236
1 changed files with 23 additions and 16 deletions
|
@ -12,27 +12,34 @@ double cos(double angle)
|
|||
return sin(angle + M_PI_2);
|
||||
}
|
||||
|
||||
double ampsin(double angle)
|
||||
static double sin_helper(double a)
|
||||
{
|
||||
double looped_angle = fmod(M_PI + angle, M_TAU);
|
||||
double looped_angle_squared = looped_angle * looped_angle;
|
||||
double a3 = a * a * a;
|
||||
double a5 = a3 * a * a;
|
||||
return a - a3 / 6.0 + a5 / 120.0;
|
||||
}
|
||||
|
||||
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;
|
||||
static double cos_helper(double a)
|
||||
{
|
||||
double a2 = a * a;
|
||||
double a4 = a2 * a2;
|
||||
return 1 - a2 / 2.0 + a4 / 24.0;
|
||||
}
|
||||
|
||||
double sin(double angle)
|
||||
{
|
||||
double vertical_scaling = M_PI_2 * M_PI_2;
|
||||
return ampsin(angle) / vertical_scaling;
|
||||
double a = fmod(angle, M_TAU);
|
||||
if (a < 0)
|
||||
a += M_TAU;
|
||||
if (a <= M_PI_2 * 0.5)
|
||||
return sin_helper(a);
|
||||
if (a <= M_PI_2)
|
||||
return cos_helper(M_PI_2 - a);
|
||||
if (a <= M_PI_2 * 1.5)
|
||||
return cos_helper(a - M_PI_2);
|
||||
if (a <= M_PI)
|
||||
return sin_helper(M_PI - a);
|
||||
return -sin(angle - M_PI);
|
||||
}
|
||||
|
||||
double pow(double x, double y)
|
||||
|
@ -55,7 +62,7 @@ double tanh(double)
|
|||
|
||||
double tan(double angle)
|
||||
{
|
||||
return ampsin(angle) / ampsin(M_PI_2 + angle);
|
||||
return sin(angle) / cos(angle);
|
||||
}
|
||||
|
||||
double sqrt(double)
|
||||
|
|
Loading…
Reference in a new issue