diff options
author | Linus Groh <mail@linusgroh.de> | 2021-11-23 22:30:27 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-11-24 17:53:00 +0000 |
commit | 1e41a8668dbe61fedfb1bcd499480b6801de40b4 (patch) | |
tree | a12f98510b8402541c6337763edf1c184d3c2135 /Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp | |
parent | a20b189eabc24eeaa5ea23dee620e8111dc62e98 (diff) | |
download | serenity-1e41a8668dbe61fedfb1bcd499480b6801de40b4.zip |
LibJS: Add sign(Crypto::SignedBigInteger const&) overload
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp index eed71e054c..e518b2ab65 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp @@ -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) { |