35 Commits
Author SHA1 Message Date
Lucas Chollet 15a07a1073 LibC+AK: Move tgamma definition from LibC to AK
This makes the tgamma function accessible from constexpr contexts and
allows us to test it in CompareAKMathAgainstMPFR.
2026-10-14 22:19:04 +02:00
Lucas Chollet 5b636c2d1d AK+LibC: Move lgamma_r definition from LibC to AK
This allows us to have a constexpr lgamma_r function and also to test it
with CompareAKMathAgainstMPFR.
2026-10-12 18:39:50 +02:00
Lucas Chollet a3b87c3293 LibC: Consider f80's explicit leading 1 in internal_to_integer
While the existing f80 path gave a valid result in the float extractor,
the rounding steps were applied as if it was a normal float.
2026-09-24 20:33:35 +02:00
Lucas Chollet d2a1d0e075 LibC: Make nextafterl return a correct value when given equal arguments
This is done by moving the check to the shared implementation.
2026-09-24 20:33:35 +02:00
Lucas Chollet 2b94b63ebc LibC: Handle edge cases correctly in erf 2026-09-24 20:33:35 +02:00
Lucas Chollet f8a9d61aa7 LibC: Compute erf values in the correct type
It's wasteful to compute everything with long double precision when we
don't need it, so this change will be required down the road when we get
to make erf precise and fast. For the time being, this is more a
cosmetic change to align this implementation with others.
2026-09-24 20:33:35 +02:00
Lucas Chollet 627b81a7e5 LibC: Implement fdim* and remquo* functions 2026-09-24 20:33:35 +02:00
Lucas Chollet 232e5ff01f LibC: Fix typo scalbnlf => scalblnf 2026-09-11 21:44:14 +02:00
Lucas Chollet 7641d1cb0e LibC: Approximate lgamma(x) directly instead of computing log(gamma(x))
This is required to obtain results for large values of `x`. The Gamma
function can produce extremely large values, causing `gamma(x)` to
return `inf` even when `lgamma(x)` can still return a finite result.
2026-08-30 14:57:35 +02:00
Lucas Chollet 01158653d2 LibC: Use a common implementation for lgamma* functions 2026-08-30 14:57:35 +02:00
Lucas Chollet 5c3721c18b LibC: Rename FP_ILOGNAN => FP_ILOGBNAN
FP_ILOGBNAN is the correct POSIX-specified name.
2026-08-22 21:48:49 +02:00
Nico Weber 341274075a LibC: Remove unused code from math.cpp
These have been dead since c5f6ba6e71 in #8743.

No behavior change.
2026-06-23 15:35:40 +02:00
Nico Weber afd64ca68e LibC: Remove unused code from math.cpp
These are dead after 92c6ae57fc in #4622.

No behavior change.
2026-06-23 15:35:40 +02:00
Nico Weber f9699604d8 LibC: Remove FE_TOMAXMAGNITUDE
It's non-standard (and a serenity-only extension, not something in
common use), unused, and riscv-only.
2026-06-19 06:09:59 +02:00
Nico Weber 56c65f576d LibC: Make internal_scalbn handle normal inputs better
It now correctly handles a normal input becoming +/-inf, and
it becoming a denormal.
2026-06-18 15:12:35 -04:00
Nico Weber ff722b30f5 LibC: Make internal_scalbn handle denormal inputs becoming inf 2026-06-18 15:12:35 -04:00
Nico Weber ba770b5444 LibC: Make internal_scalbn handle denormal inputs
We now handle negative shifts, and denormal -> normal transitions
for large-enough shifts.
2026-06-18 15:12:35 -04:00
Nico Weber 509b7692f0 LibC: Remove dead code form internal_scalbn()
We know that x != 0 and extractor.exponent == 0 at the bottom
of the function, meaning mantissa must be != 0.

And the `extractor.exponent = exponent + 1;` store overwrites
the store on the line above. (Presumably, the line above meant
to shift `mantissa` instead.)

No behavior change.
2026-06-18 15:12:35 -04:00
matyalatte da73013dd6 LibC: Replace llroundd with llroundl 2025-04-21 11:07:53 -04:00
Nico Weber 48a28cffd5 AK: Make FloatExtractor use bit_cast<>() instead of a union
The motivation is to allow functions that use FloatExtractor to be
constexpr.  Type punning through a union will never work in constexpr.

In practice, bit_cast<>()ing bit fields also does not yet work in clang,
but that's just a bug and it will work eventually (and it does already
work in gcc): https://github.com/llvm/llvm-project/issues/54018

No behavior change.
2025-01-02 09:56:31 -05:00
Sönke Holz 7823600f7a LibC: Make rint{,f,l}() AK-backed 2024-12-30 14:46:27 -05:00
Nico Weber 982c8cc7fb AK+LibC: Move generic copysign() into AK 2024-12-24 13:11:07 -05:00
kleines Filmröllchen e74b34b69e LibC: Fix extended floating point software rounding
Contrary to IEEE formats, x86's 80-bit extended floats need the topmost
mantissa bit to be 1 or else a special kind of NaN is produced. We fix
this by reinserting the special bit if necessary.
2024-04-23 19:18:09 -06:00
kleines Filmröllchen 0c1ad05f50 LibC: Add rounding specializations for RISC-V
Whenever the floating-point values are in integer range, we can use the
various FCVT functions with static rounding mode to perform fast
rounding. I took this opportunity to clean up the architecture
differentiation for these functions, which allows us to use the software
rounding implementation for all extreme and unimplemented cases,
including AArch64.

Also adds more round & trunc tests.
2024-04-23 19:18:09 -06:00
kleines Filmröllchen 334f5e319c LibC: Prevent undefined shift in internal_to_integer
New tests will hit a dead bit count of 64, leading to an undefined
shift.
2024-04-23 19:18:09 -06:00
Sönke Holz 6824d2a788 Userland+Tests: Add initial riscv64 support 2023-11-10 10:30:08 -07:00
Bastiaan van der Plaat 5870a1a9a1 AK: Remove rarely used ExtraMathConstants.h 2023-10-23 12:04:51 +01:00
Nico Weber 97b7e494e4 Everywhere: Use ARCH(AARCH64) instead of AK_ARCH_AARCH64
The former is typo-resistant after 349e54d537, so make use of that.
2023-04-14 19:15:19 +02:00
Ben Wiederhake 3281050359 Everywhere: Remove "LibC/" includes, add lint-rule against it 2023-01-07 10:01:37 -07:00
Ben Wiederhake 6b7ce19161 Everywhere: Remove unused includes of LibC/stdlib.h
These instances were detected by searching for files that include
stdlib.h, but don't match the regex:

\\b(_abort|abort|abs|aligned_alloc|arc4random|arc4random_buf|arc4random_
uniform|atexit|atof|atoi|atol|atoll|bsearch|calloc|clearenv|div|div_t|ex
it|_Exit|EXIT_FAILURE|EXIT_SUCCESS|free|getenv|getprogname|grantpt|labs|
ldiv|ldiv_t|llabs|lldiv|lldiv_t|malloc|malloc_good_size|malloc_size|mble
n|mbstowcs|mbtowc|mkdtemp|mkstemp|mkstemps|mktemp|posix_memalign|posix_o
penpt|ptsname|ptsname_r|putenv|qsort|qsort_r|rand|RAND_MAX|random|reallo
c|realpath|secure_getenv|serenity_dump_malloc_stats|serenity_setenv|sete
nv|setprogname|srand|srandom|strtod|strtof|strtol|strtold|strtoll|strtou
l|strtoull|system|unlockpt|unsetenv|wcstombs|wctomb)\\b

(Without the linebreaks.)

This regex is pessimistic, so there might be more files that don't
actually use anything from the stdlib.

In theory, one might use LibCPP to detect things like this
automatically, but let's do this one step after another.
2023-01-02 20:27:20 -05:00
Liav A 92da98822a LibC: Remove i686 support 2022-12-28 11:53:41 +01:00
Dan Klishch 17c9a3e8d9 AK+LibC+LibCrypto: Move FloatExtractor to AK/FloatingPoint.h 2022-11-03 20:17:09 -06:00
Gunnar Beutner 31bd5b1a02 AK+Userland: Stub out code that isn't currently implemented on AARCH64
Even though this almost certainly wouldn't run properly even if we had
a working kernel for AARCH64 this at least lets us build all the
userland binaries.
2022-10-14 13:01:13 +02:00
Nico Weber 2af028132a AK+Everywhere: Add AK_COMPILER_{GCC,CLANG} and use them most places
Doesn't use them in libc headers so that those don't have to pull in
AK/Platform.h.

AK_COMPILER_GCC is set _only_ for gcc, not for clang too. (__GNUC__ is
defined in clang builds as well.) Using AK_COMPILER_GCC simplifies
things some.

AK_COMPILER_CLANG isn't as much of a win, other than that it's
consistent with AK_COMPILER_GCC.
2022-10-04 23:35:07 +01:00
Tim Schumacher 81d46fa100 LibM: Move the math standard library to LibC 2022-09-16 16:09:19 +00:00