summaryrefslogtreecommitdiff
path: root/src/mongo/platform/decimal128_test.cpp
diff options
context:
space:
mode:
authorJames Wahlin <james@mongodb.com>2019-02-14 16:12:50 -0500
committerJames Wahlin <james@mongodb.com>2019-02-20 08:59:01 -0500
commit5aa3f6dbc5e31beaf40e0828f7a24ecf71fb42f9 (patch)
tree6f003bf9b8b6fd2f0144f69e69e69cb7bc6205dd /src/mongo/platform/decimal128_test.cpp
parent79a050141e79dc267f8723adb48b191652ba9fce (diff)
downloadmongo-5aa3f6dbc5e31beaf40e0828f7a24ecf71fb42f9.tar.gz
SERVER-39487 Decimal128::squareRoot() returns result for Decimal128::exponential()
Diffstat (limited to 'src/mongo/platform/decimal128_test.cpp')
-rw-r--r--src/mongo/platform/decimal128_test.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/mongo/platform/decimal128_test.cpp b/src/mongo/platform/decimal128_test.cpp
index 53c415365a3..dfce92f4fb8 100644
--- a/src/mongo/platform/decimal128_test.cpp
+++ b/src/mongo/platform/decimal128_test.cpp
@@ -1413,6 +1413,30 @@ void assertDecimal128ExactlyEqual(Decimal128 x, Decimal128 y) {
ASSERT_EQUALS(x.getValue().low64, y.getValue().low64);
}
+TEST(Decimal128Test, TestExp) {
+ assertDecimal128ApproxEqual(Decimal128("-1").exponential(),
+ Decimal128("0.3678794411714423215955237701614609"));
+ assertDecimal128ApproxEqual(Decimal128("0").exponential(), Decimal128("1"));
+ assertDecimal128ApproxEqual(Decimal128("1").exponential(),
+ Decimal128("2.718281828459045235360287471352662"));
+ assertDecimal128ApproxEqual(Decimal128("1.5").exponential(),
+ Decimal128("4.481689070338064822602055460119276"));
+ assertDecimal128ApproxEqual(Decimal128("1.79769313486231E+308")
+ .exponential(Decimal128::RoundingMode::kRoundTowardNegative),
+ Decimal128("9.999999999999999999999999999999999E+6144"));
+}
+
+TEST(Decimal128Test, TestSqrt) {
+ assertDecimal128ApproxEqual(Decimal128("0").squareRoot(), Decimal128("0"));
+ assertDecimal128ApproxEqual(Decimal128("1").squareRoot(), Decimal128("1"));
+ assertDecimal128ApproxEqual(Decimal128("25").squareRoot(), Decimal128("5"));
+ assertDecimal128ApproxEqual(Decimal128("25.5").squareRoot(),
+ Decimal128("5.049752469181038976681692958534800"));
+ assertDecimal128ApproxEqual(Decimal128("1.79769313486231E+308")
+ .squareRoot(Decimal128::RoundingMode::kRoundTowardNegative),
+ Decimal128("1.340780792994257506864497209340836E+154"));
+}
+
TEST(Decimal128Test, TestAsin) {
assertDecimal128ApproxEqual(Decimal128("-1.0").asin(), Decimal128("-1.57079632679"));
assertDecimal128ApproxEqual(Decimal128("-0.9").asin(), Decimal128("-1.119769515"));