LibM: Add ilogb and logb
This commit is contained in:
parent
190952675e
commit
352b383280
Notes:
sideshowbarker
2024-07-18 21:36:02 +09:00
Author: https://github.com/RealKC Commit: https://github.com/SerenityOS/serenity/commit/352b383280d Pull-request: https://github.com/SerenityOS/serenity/pull/5688 Issue: https://github.com/SerenityOS/serenity/issues/4282 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/BenWiederhake Reviewed-by: https://github.com/awesomekling
2 changed files with 60 additions and 0 deletions
|
@ -243,6 +243,26 @@ static FloatType internal_nextafter(FloatType x, bool up)
|
||||||
return extractor.d;
|
return extractor.d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename FloatT>
|
||||||
|
static int internal_ilogb(FloatT x) NOEXCEPT
|
||||||
|
{
|
||||||
|
if (x == 0)
|
||||||
|
return FP_ILOGB0;
|
||||||
|
|
||||||
|
if (isnan(x))
|
||||||
|
return FP_ILOGNAN;
|
||||||
|
|
||||||
|
if (!isfinite(x))
|
||||||
|
return INT_MAX;
|
||||||
|
|
||||||
|
using Extractor = FloatExtractor<FloatT>;
|
||||||
|
|
||||||
|
Extractor extractor;
|
||||||
|
extractor.d = x;
|
||||||
|
|
||||||
|
return (int)extractor.exponent - Extractor::exponent_bias;
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
double trunc(double x) NOEXCEPT
|
double trunc(double x) NOEXCEPT
|
||||||
|
@ -547,6 +567,36 @@ double fabs(double value) NOEXCEPT
|
||||||
return value < 0 ? -value : value;
|
return value < 0 ? -value : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ilogbl(long double x) NOEXCEPT
|
||||||
|
{
|
||||||
|
return internal_ilogb(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ilogb(double x) NOEXCEPT
|
||||||
|
{
|
||||||
|
return internal_ilogb(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ilogbf(float x) NOEXCEPT
|
||||||
|
{
|
||||||
|
return internal_ilogb(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
long double logbl(long double x) NOEXCEPT
|
||||||
|
{
|
||||||
|
return ilogbl(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
double logb(double x) NOEXCEPT
|
||||||
|
{
|
||||||
|
return ilogb(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
float logbf(float x) NOEXCEPT
|
||||||
|
{
|
||||||
|
return ilogbf(x);
|
||||||
|
}
|
||||||
|
|
||||||
double log2(double x) NOEXCEPT
|
double log2(double x) NOEXCEPT
|
||||||
{
|
{
|
||||||
double ret = 0.0;
|
double ret = 0.0;
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
#if __cplusplus >= 201103L
|
#if __cplusplus >= 201103L
|
||||||
|
@ -128,6 +129,15 @@ float ldexpf(float, int exp) NOEXCEPT;
|
||||||
double pow(double x, double y) NOEXCEPT;
|
double pow(double x, double y) NOEXCEPT;
|
||||||
float powf(float x, float y) NOEXCEPT;
|
float powf(float x, float y) NOEXCEPT;
|
||||||
|
|
||||||
|
#define FP_ILOGB0 INT_MIN
|
||||||
|
#define FP_ILOGNAN INT_MAX
|
||||||
|
|
||||||
|
int ilogbl(long double) NOEXCEPT;
|
||||||
|
int ilogb(double) NOEXCEPT;
|
||||||
|
int ilogbf(float) NOEXCEPT;
|
||||||
|
long double logbl(long double) NOEXCEPT;
|
||||||
|
double logb(double) NOEXCEPT;
|
||||||
|
float logbf(float) NOEXCEPT;
|
||||||
double log2(double) NOEXCEPT;
|
double log2(double) NOEXCEPT;
|
||||||
float log2f(float) NOEXCEPT;
|
float log2f(float) NOEXCEPT;
|
||||||
long double log2l(long double) NOEXCEPT;
|
long double log2l(long double) NOEXCEPT;
|
||||||
|
|
Loading…
Add table
Reference in a new issue