mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:17:35 +00:00
AK: Add FixedPoint base 2 logarithm
The log base 2 is implemented using the binary logarithm algorithm by Clay Turner (see the link in the comment)
This commit is contained in:
parent
30002c2ccb
commit
98058f7efe
2 changed files with 48 additions and 0 deletions
|
@ -7,6 +7,7 @@
|
|||
#include <LibTest/TestCase.h>
|
||||
|
||||
#include <AK/FixedPoint.h>
|
||||
#include <AK/NumericLimits.h>
|
||||
|
||||
using Type = FixedPoint<4>;
|
||||
|
||||
|
@ -73,6 +74,18 @@ TEST_CASE(rounding)
|
|||
EXPECT_EQ(Type(-1.5).ltrunk(), -1);
|
||||
}
|
||||
|
||||
TEST_CASE(logarithm)
|
||||
{
|
||||
EXPECT_EQ(Type(0).log2().raw(), NumericLimits<int>::min());
|
||||
EXPECT_EQ(Type(1).log2(), Type(0));
|
||||
EXPECT_EQ(Type(2).log2(), Type(1));
|
||||
EXPECT_EQ(Type(8).log2(), Type(3));
|
||||
EXPECT_EQ(Type(0.5).log2(), Type(-1));
|
||||
|
||||
EXPECT_EQ(Type(22.627416997969520780827019587355).log2(), Type(4.4375));
|
||||
EXPECT_EQ(Type(3088).log2(), Type(11.592457037268080419637304576833));
|
||||
}
|
||||
|
||||
TEST_CASE(comparison)
|
||||
{
|
||||
EXPECT(Type(0) < 1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue