mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-14 21:42:19 +00:00
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.
This commit is contained in:
parent
0c1ad05f50
commit
e74b34b69e
Notes:
sideshowbarker
2024-07-17 04:09:56 +09:00
Author: https://github.com/kleinesfilmroellchen
Commit: e74b34b69e
Pull-request: https://github.com/SerenityOS/serenity/pull/24090
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/DanShaders
1 changed files with 7 additions and 0 deletions
|
@ -99,6 +99,13 @@ static FloatType internal_to_integer(FloatType x, RoundingMode rounding_mode)
|
|||
auto dead_mask = dead_bitcount == sizeof(typename Extractor::ComponentType) * 8 ? ~zero : (one << dead_bitcount) - 1;
|
||||
auto dead_bits = extractor.mantissa & dead_mask;
|
||||
extractor.mantissa &= ~dead_mask;
|
||||
#ifdef AK_HAS_FLOAT_80
|
||||
if constexpr (IsSame<f80, FloatType>) {
|
||||
// x86 80-bit extended floating point requires the top mantissa bit to always be 1, or we get a special Intel NaN.
|
||||
if (extractor.mantissa == 0)
|
||||
extractor.mantissa = one << (Extractor::mantissa_bits - 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
auto nonhalf_fraction_mask = dead_mask >> 1;
|
||||
has_nonhalf_fraction = (dead_bits & nonhalf_fraction_mask) != 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue