Skip to content

Commit

Permalink
feat: add asinh function to math. (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
CusiniM authored Nov 5, 2024
1 parent becf140 commit c9d97b4
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,35 @@ __half2 log( __half2 const x )

#endif

/**
* @return asinh of @p x.
* @param x the argument.
* @note This set of overloads is valid for any numeric type. If @p x is integral it is converted to @c double
* and the return type is double.
*/
LVARRAY_HOST_DEVICE LVARRAY_FORCE_INLINE
float asinh( float const x )
{
#if defined(LVARRAY_DEVICE_COMPILE)
return ::asinhf( x );
#else
return std::asinh( x );
#endif
}

/// @copydoc asinh( float )
template< typename T >
LVARRAY_HOST_DEVICE LVARRAY_FORCE_INLINE
double asinh( T const x )
{
#if defined(LVARRAY_DEVICE_COMPILE)
return ::asinh( double( x ) );
#else
return std::asinh( x );
#endif
}


///@}

} // namespace math
Expand Down
40 changes: 40 additions & 0 deletions unitTests/testMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,46 @@ TYPED_TEST( TestMath, exponential )
this->exponential();
}

template< typename T_POLICY_PAIR >
struct TestComplexMath : public ::testing::Test
{
using T = typename T_POLICY_PAIR::first_type;
using POLICY = typename T_POLICY_PAIR::second_type;

void asinh()
{
using FloatingPoint = decltype( math::asinh( T() ) );
forall< POLICY >( 1, [] LVARRAY_HOST_DEVICE ( int )
{
FloatingPoint const epsilon = NumericLimitsNC< FloatingPoint >{}.epsilon;

PORTABLE_EXPECT_NEAR( math::asinh( T( 5.0 ) ), FloatingPoint( ::asinh( 5.0 ) ), epsilon );
PORTABLE_EXPECT_NEAR( math::asinh( T( 5.0 ) ), FloatingPoint( ::asinh( 5.0 ) ), epsilon );
} );
}
};

using TestComplexMathTypes = ::testing::Types<
std::pair< int, serialPolicy >
, std::pair< long int, serialPolicy >
, std::pair< long long int, serialPolicy >
, std::pair< float, serialPolicy >
, std::pair< double, serialPolicy >
#if defined( LVARRAY_USE_CUDA ) || defined( LVARRAY_USE_HIP )
, std::pair< int, parallelDevicePolicy< 32 > >
, std::pair< long int, parallelDevicePolicy< 32 > >
, std::pair< long long int, parallelDevicePolicy< 32 > >
, std::pair< float, parallelDevicePolicy< 32 > >
, std::pair< double, parallelDevicePolicy< 32 > >
#endif
>;

TYPED_TEST_SUITE( TestComplexMath, TestComplexMathTypes, );

TYPED_TEST( TestComplexMath, asinh )
{
this->asinh();
}

template< typename T_POLICY_PAIR >
struct TestMath2 : public ::testing::Test
Expand Down

0 comments on commit c9d97b4

Please sign in to comment.