1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-29 13:47:34 +00:00

AK: Add FloatingPoint.h

This is a set of functions that allow you to convert between arbitrary
IEEE 754 floating point types, as long as they can be represented
within 64 bits. Conversion methods between floats and doubles are
provided, as well as a generic `float_to_float()`.

Example usage:

  #include <AK/FloatingPoint.h>

  double val = 1.234;
  auto weird_f16 =
      convert_from_native_double<FloatingPointBits<0, 6, 10>>(val);

Signed and unsigned floats are supported, and both NaN and +/-Inf are
handled correctly. Values that do not fit in the target floating point
type are clamped.
This commit is contained in:
Jelle Raaijmakers 2022-02-05 02:23:27 +01:00 committed by Andreas Kling
parent f1cd6453ae
commit 8483064b59
3 changed files with 279 additions and 0 deletions

View file

@ -26,6 +26,7 @@ set(AK_TEST_SOURCES
TestEnumBits.cpp
TestFind.cpp
TestFixedArray.cpp
TestFloatingPoint.cpp
TestFormat.cpp
TestGenericLexer.cpp
TestHashFunctions.cpp