mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
LibM: Implement floating point variants of various math functions
This commit is contained in:
parent
3b8713a9df
commit
24b5fd4c4c
Notes:
sideshowbarker
2024-07-19 09:03:44 +09:00
Author: https://github.com/vkoskiv Commit: https://github.com/SerenityOS/serenity/commit/24b5fd4c4c1 Pull-request: https://github.com/SerenityOS/serenity/pull/1297
2 changed files with 55 additions and 0 deletions
|
@ -69,6 +69,11 @@ double cos(double angle)
|
|||
return sin(angle + M_PI_2);
|
||||
}
|
||||
|
||||
float cosf(float angle)
|
||||
{
|
||||
return sinf(angle + M_PI_2);
|
||||
}
|
||||
|
||||
// This can also be done with a taylor expansion, but for
|
||||
// now this works pretty well (and doesn't mess anything up
|
||||
// in quake in particular, which is very Floating-Point precision
|
||||
|
@ -84,12 +89,27 @@ double sin(double angle)
|
|||
return ret;
|
||||
}
|
||||
|
||||
float sinf(float angle)
|
||||
{
|
||||
float ret = 0.0f;
|
||||
__asm__(
|
||||
"fsin"
|
||||
: "=t"(ret)
|
||||
: "0"(angle));
|
||||
return ret;
|
||||
}
|
||||
|
||||
double pow(double x, double y)
|
||||
{
|
||||
//FIXME: Extremely unlikely to be standards compliant.
|
||||
return exp(y * log(x));
|
||||
}
|
||||
|
||||
float powf(float x, float y)
|
||||
{
|
||||
return (float)exp((double)y * log((double)x));
|
||||
}
|
||||
|
||||
double ldexp(double x, int exp)
|
||||
{
|
||||
// FIXME: Please fix me. I am naive.
|
||||
|
@ -139,6 +159,15 @@ double sqrt(double x)
|
|||
return res;
|
||||
}
|
||||
|
||||
float sqrtf(float x)
|
||||
{
|
||||
float res;
|
||||
__asm__("fsqrt"
|
||||
: "=t"(res)
|
||||
: "0"(x));
|
||||
return res;
|
||||
}
|
||||
|
||||
double sinh(double x)
|
||||
{
|
||||
double exponentiated = exp(x);
|
||||
|
@ -167,6 +196,11 @@ double log(double x)
|
|||
return y + 2 * (x - exponentiated) / (x + exponentiated);
|
||||
}
|
||||
|
||||
float logf(float x)
|
||||
{
|
||||
return (float)log(x);
|
||||
}
|
||||
|
||||
double fmod(double index, double period)
|
||||
{
|
||||
return index - trunc(index / period) * period;
|
||||
|
@ -208,6 +242,11 @@ double exp(double exponent)
|
|||
return result * taylor_series_result;
|
||||
}
|
||||
|
||||
float expf(float exponent)
|
||||
{
|
||||
return (float)exp(exponent);
|
||||
}
|
||||
|
||||
double cosh(double x)
|
||||
{
|
||||
double exponentiated = exp(-x);
|
||||
|
@ -232,6 +271,11 @@ double atan2(double y, double x)
|
|||
return atan(y / x) - M_PI;
|
||||
}
|
||||
|
||||
float atan2f(float y, float x)
|
||||
{
|
||||
return (float)atan2(y, x);
|
||||
}
|
||||
|
||||
double atan(double x)
|
||||
{
|
||||
if (x < 0)
|
||||
|
@ -265,11 +309,21 @@ double asin(double x)
|
|||
return value;
|
||||
}
|
||||
|
||||
float asinf(float x)
|
||||
{
|
||||
return (float)asin(x);
|
||||
}
|
||||
|
||||
double acos(double x)
|
||||
{
|
||||
return M_PI_2 - asin(x);
|
||||
}
|
||||
|
||||
float acosf(float x)
|
||||
{
|
||||
return M_PI_2 - asinf(x);
|
||||
}
|
||||
|
||||
double fabs(double value)
|
||||
{
|
||||
return value < 0 ? -value : value;
|
||||
|
|
|
@ -84,6 +84,7 @@ double ldexp(double, int exp);
|
|||
float ldexpf(float, int exp);
|
||||
|
||||
double pow(double x, double y);
|
||||
float powf(float x, float y);
|
||||
|
||||
double log2(double);
|
||||
float log2f(float);
|
||||
|
|
Loading…
Add table
Reference in a new issue