1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:37:37 +00:00

LibJS: Add sign(Crypto::SignedBigInteger const&) overload

This commit is contained in:
Linus Groh 2021-11-23 22:30:27 +00:00
parent a20b189eab
commit 1e41a8668d
3 changed files with 18 additions and 9 deletions

View file

@ -952,6 +952,20 @@ double sign(double n)
return 1;
}
double sign(Crypto::SignedBigInteger const& n)
{
// 1. If n is NaN, n is +0𝔽, or n is 0𝔽, return n.
if (n == Crypto::SignedBigInteger { 0 })
return n.is_negative() ? -0 : 0;
// 2. If n < +0𝔽, return 1𝔽.
if (n.is_negative())
return -1;
// 3. Return 1𝔽.
return 1;
}
// 13.29 ConstrainToRange ( x, minimum, maximum ), https://tc39.es/proposal-temporal/#sec-temporal-constraintorange
double constrain_to_range(double x, double minimum, double maximum)
{