summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-11-23 22:30:27 +0000
committerLinus Groh <mail@linusgroh.de>2021-11-24 17:53:00 +0000
commit1e41a8668dbe61fedfb1bcd499480b6801de40b4 (patch)
treea12f98510b8402541c6337763edf1c184d3c2135 /Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
parenta20b189eabc24eeaa5ea23dee620e8111dc62e98 (diff)
downloadserenity-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.cpp14
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)
{