From 190952675e1f0d4520a8e5987fefeb1a593f519a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C8=9Bca=20Dumitru?= Date: Sun, 7 Mar 2021 20:36:08 +0200 Subject: [PATCH] LibM: Specialiase FloatExtractor for long double as well --- Userland/Libraries/LibM/math.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Userland/Libraries/LibM/math.cpp b/Userland/Libraries/LibM/math.cpp index 47ab3e537c..8a7a0f15c3 100644 --- a/Userland/Libraries/LibM/math.cpp +++ b/Userland/Libraries/LibM/math.cpp @@ -24,6 +24,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +#include #include #include #include @@ -67,6 +69,24 @@ enum class RoundingMode { template union FloatExtractor; +#if ARCH(I386) || ARCH(X86_64) +// This assumes long double is 80 bits, which is true with GCC on Intel platforms +template<> +union FloatExtractor { + static const int mantissa_bits = 64; + static const unsigned long long mantissa_max = ~0u; + static const int exponent_bias = 16383; + static const int exponent_bits = 15; + static const unsigned exponent_max = 32767; + struct { + unsigned long long mantissa; + unsigned exponent : 15; + unsigned sign : 1; + }; + long double d; +}; +#endif + template<> union FloatExtractor { static const int mantissa_bits = 52;