@@ -43,6 +43,9 @@ namespace arrow {
4343namespace compute {
4444namespace {
4545
46+ // 2.718281828459045090795598298427648842334747314453125
47+ constexpr double kEuler64 = 0x1 .5bf0a8b145769p+1 ;
48+
4649using IntegralTypes = testing::Types<Int8Type, Int16Type, Int32Type, Int64Type, UInt8Type,
4750 UInt16Type, UInt32Type, UInt64Type>;
4851
@@ -1485,8 +1488,7 @@ TYPED_TEST(TestUnaryArithmeticUnsigned, Exp) {
14851488 this ->AssertUnaryOp (
14861489 exp, " [null, 1, 10]" ,
14871490 ArrayFromJSON (float64 (), " [null, 2.718281828459045, 22026.465794806718]" ));
1488- this ->AssertUnaryOp (exp, this ->MakeScalar (1 ),
1489- arrow::MakeScalar<double >(2 .718281828459045F ));
1491+ this ->AssertUnaryOp (exp, this ->MakeScalar (1 ), arrow::MakeScalar (kEuler64 ));
14901492}
14911493
14921494TYPED_TEST (TestUnaryArithmeticSigned, Exp) {
@@ -1502,8 +1504,7 @@ TYPED_TEST(TestUnaryArithmeticSigned, Exp) {
15021504 ArrayFromJSON (float64 (),
15031505 " [0.000045399929762484854, 0.36787944117144233, "
15041506 " null, 2.718281828459045, 22026.465794806718]" ));
1505- this ->AssertUnaryOp (exp, this ->MakeScalar (1 ),
1506- arrow::MakeScalar<double >(2 .718281828459045F ));
1507+ this ->AssertUnaryOp (exp, this ->MakeScalar (1 ), arrow::MakeScalar (kEuler64 ));
15071508}
15081509
15091510TYPED_TEST (TestUnaryArithmeticFloating, Exp) {
@@ -1563,6 +1564,101 @@ TEST_F(TestUnaryArithmeticDecimal, Exp) {
15631564 }
15641565}
15651566
1567+ TYPED_TEST (TestUnaryArithmeticUnsigned, Expm1) {
1568+ auto expm1 = [](const Datum& arg, ArithmeticOptions, ExecContext* ctx) {
1569+ return Expm1 (arg, ctx);
1570+ };
1571+ // Empty arrays
1572+ this ->AssertUnaryOp (expm1, " []" , ArrayFromJSON (float64 (), " []" ));
1573+ // Array with nulls
1574+ this ->AssertUnaryOp (expm1, " [null]" , ArrayFromJSON (float64 (), " [null]" ));
1575+ this ->AssertUnaryOp (expm1, this ->MakeNullScalar (), arrow::MakeNullScalar (float64 ()));
1576+ this ->AssertUnaryOp (
1577+ expm1, " [null, 0, 1, 10]" ,
1578+ ArrayFromJSON (float64 (), " [null, 0.0, 1.718281828459045, 22025.465794806718]" ));
1579+ this ->AssertUnaryOp (expm1, this ->MakeScalar (1 ), arrow::MakeScalar (kEuler64 - 1.0 ));
1580+ }
1581+
1582+ TYPED_TEST (TestUnaryArithmeticSigned, Expm1) {
1583+ auto expm1 = [](const Datum& arg, ArithmeticOptions, ExecContext* ctx) {
1584+ return Expm1 (arg, ctx);
1585+ };
1586+ // Empty arrays
1587+ this ->AssertUnaryOp (expm1, " []" , ArrayFromJSON (float64 (), " []" ));
1588+ // Array with nulls
1589+ this ->AssertUnaryOp (expm1, " [null]" , ArrayFromJSON (float64 (), " [null]" ));
1590+ this ->AssertUnaryOp (expm1, this ->MakeNullScalar (), arrow::MakeNullScalar (float64 ()));
1591+ this ->AssertUnaryOp (expm1, " [-10, -1, 0, null, 1, 10]" ,
1592+ ArrayFromJSON (float64 (),
1593+ " [-0.9999546000702375, -0.6321205588285577, 0.0, "
1594+ " null, 1.718281828459045, 22025.465794806718]" ));
1595+ this ->AssertUnaryOp (expm1, this ->MakeScalar (1 ), arrow::MakeScalar (kEuler64 - 1.0 ));
1596+ }
1597+
1598+ TYPED_TEST (TestUnaryArithmeticFloating, Expm1) {
1599+ using CType = typename TestFixture::CType;
1600+
1601+ auto min = std::numeric_limits<CType>::lowest ();
1602+ auto max = std::numeric_limits<CType>::max ();
1603+
1604+ auto expm1 = [](const Datum& arg, ArithmeticOptions, ExecContext* ctx) {
1605+ return Expm1 (arg, ctx);
1606+ };
1607+ // Empty arrays
1608+ this ->AssertUnaryOp (expm1, " []" , " []" );
1609+ // Array with nulls
1610+ this ->AssertUnaryOp (expm1, " [null]" , " [null]" );
1611+ this ->AssertUnaryOp (expm1, this ->MakeNullScalar (), this ->MakeNullScalar ());
1612+ this ->AssertUnaryOp (expm1, " [-1.0, 0.0, 0.1, 0.00000001, null, 10.0]" ,
1613+ " [-0.6321205588285577, 0.0, "
1614+ " 0.10517091807564763, 0.000000010000000050000001, "
1615+ " null, 22025.465794806718]" );
1616+ // Ordinary arrays (positive, negative, fractional, and zero inputs)
1617+ this ->AssertUnaryOp (expm1, " [-10.0, 0.0, 0.1, 0.00000001, 0.5, 1.0]" ,
1618+ " [-0.9999546000702375, 0.0, "
1619+ " 0.10517091807564763, 0.000000010000000050000001, "
1620+ " 0.6487212707001282, 1.718281828459045]" );
1621+ this ->AssertUnaryOp (expm1, 1 .3F , 2 .6692964926535487F );
1622+ this ->AssertUnaryOp (expm1, this ->MakeScalar (1 .3F ),
1623+ this ->MakeScalar (2 .6692964926535487F ));
1624+ // Arrays with infinites
1625+ this ->AssertUnaryOp (expm1, " [-Inf, Inf]" , " [-1, Inf]" );
1626+ // Arrays with NaNs
1627+ this ->SetNansEqual (true );
1628+ this ->AssertUnaryOp (expm1, " [NaN]" , " [NaN]" );
1629+ // Min/max
1630+ this ->AssertUnaryOp (expm1, min, -1.0 );
1631+ this ->AssertUnaryOp (expm1, max, std::numeric_limits<CType>::infinity ());
1632+ }
1633+
1634+ TEST_F (TestUnaryArithmeticDecimal, Expm1) {
1635+ auto max128 = Decimal128::GetMaxValue (38 );
1636+ auto max256 = Decimal256::GetMaxValue (76 );
1637+ const auto func = " expm1" ;
1638+ for (const auto & ty : PositiveScaleTypes ()) {
1639+ CheckScalar (func, {ArrayFromJSON (ty, R"( [])" )}, ArrayFromJSON (float64 (), " []" ));
1640+ CheckScalar (
1641+ func, {ArrayFromJSON (ty, R"( ["-1.00", "0.00", "0.10", "0.01", "10.00", null])" )},
1642+ ArrayFromJSON (float64 (),
1643+ " [-0.6321205588285577, 0.0, "
1644+ " 0.10517091807564763, 0.010050167084168058, "
1645+ " 22025.465794806718, null]" ));
1646+ }
1647+ CheckScalar (func, {std::make_shared<Decimal128Scalar>(max128, decimal128 (38 , 0 ))},
1648+ ScalarFromJSON (float64 (), " Inf" ));
1649+ CheckScalar (func, {std::make_shared<Decimal128Scalar>(-max128, decimal128 (38 , 0 ))},
1650+ ScalarFromJSON (float64 (), " -1.0" ));
1651+ CheckScalar (func, {std::make_shared<Decimal256Scalar>(max256, decimal256 (76 , 0 ))},
1652+ ScalarFromJSON (float64 (), " Inf" ));
1653+ CheckScalar (func, {std::make_shared<Decimal256Scalar>(-max256, decimal256 (76 , 0 ))},
1654+ ScalarFromJSON (float64 (), " -1.0" ));
1655+ for (const auto & ty : NegativeScaleTypes ()) {
1656+ CheckScalar (func, {ArrayFromJSON (ty, R"( [])" )}, ArrayFromJSON (float64 (), " []" ));
1657+ CheckScalar (func, {DecimalArrayFromJSON (ty, R"( ["12E2", "0", "-42E2", null])" )},
1658+ ArrayFromJSON (float64 (), " [Inf, 0.0, -1.0, null]" ));
1659+ }
1660+ }
1661+
15661662TEST_F (TestUnaryArithmeticDecimal, Log) {
15671663 std::vector<std::string> unchecked = {" ln" , " log2" , " log10" , " log1p" };
15681664 std::vector<std::string> checked = {" ln_checked" , " log2_checked" , " log10_checked" ,
0 commit comments