Fix an issue where the remainder function not well supported on MSVC

Also fix a minor conversion warning.
This commit is contained in:
Kenneth Moreland 2015-06-30 08:50:02 -06:00
parent 21205d0785
commit f426b16daf
2 changed files with 128 additions and 107 deletions

@ -1099,14 +1099,14 @@ VTKM_EXEC_CONT_EXPORT
vtkm::Float32 Log2(vtkm::Float32 x) {
//windows and boost don't provide log2
//0.6931471805599453 is the constant value of log(2)
const vtkm::Float32 log2v(0.6931471805599453);
const vtkm::Float32 log2v = 0.6931471805599453f;
return vtkm::Log(x)/log2v;
}
VTKM_EXEC_CONT_EXPORT
vtkm::Float64 Log2(vtkm::Float64 x) {
//windows and boost don't provide log2
//0.6931471805599453 is the constant value of log(2)
const vtkm::Float64 log2v(0.6931471805599453);
const vtkm::Float64 log2v = 0.6931471805599453;
return vtkm::Log(x)/log2v;
}
#else // !VTKM_USE_BOOST_MATH
@ -1542,89 +1542,6 @@ bool IsFinite(T x)
return (isfinite(x) != 0);
}
//-----------------------------------------------------------------------------
/// Computes the remainder on division of 2 floating point numbers. The return
/// value is \p numerator - n \p denominator, where n is the quotient of \p
/// numerator divided by \p denominator rounded towards zero to an integer. For
/// example, <tt>FMod(6.5, 2.3)</tt> returns 1.9, which is 6.5 - 2*2.3.
///
VTKM_EXEC_CONT_EXPORT
vtkm::Float32 FMod(vtkm::Float32 x, vtkm::Float32 y) {
return VTKM_SYS_MATH_FUNCTION_32(fmod)(x,y);
}
VTKM_EXEC_CONT_EXPORT
vtkm::Float64 FMod(vtkm::Float64 x, vtkm::Float64 y) {
return VTKM_SYS_MATH_FUNCTION_64(fmod)(x,y);
}
/// Computes the remainder on division of 2 floating point numbers. The return
/// value is \p numerator - n \p denominator, where n is the quotient of \p
/// numerator divided by \p denominator rounded towards the nearest integer
/// (instead of toward zero like FMod). For example, <tt>FMod(6.5, 2.3)</tt>
/// returns -0.4, which is 6.5 - 3*2.3.
///
VTKM_EXEC_CONT_EXPORT
vtkm::Float32 Remainder(vtkm::Float32 x, vtkm::Float32 y) {
return VTKM_SYS_MATH_FUNCTION_32(remainder)(x,y);
}
VTKM_EXEC_CONT_EXPORT
vtkm::Float64 Remainder(vtkm::Float64 x, vtkm::Float64 y) {
return VTKM_SYS_MATH_FUNCTION_64(remainder)(x,y);
}
/// Returns the remainder on division of 2 floating point numbers just like
/// Remainder. In addition, this function also returns the \c quotient used to
/// get that remainder.
///
template<typename QType>
VTKM_EXEC_CONT_EXPORT
vtkm::Float32 RemainderQuotient(vtkm::Float32 numerator,
vtkm::Float32 denominator,
QType &quotient)
{
#ifdef VTKM_USE_BOOST_MATH
quotient = static_cast<QType>(boost::math::round(numerator/denominator));
return vtkm::Remainder(numerator, denominator);
#else
int iQuotient;
vtkm::Float32 result =
VTKM_SYS_MATH_FUNCTION_32(remquo)(numerator, denominator, &iQuotient);
quotient = iQuotient;
return result;
#endif
}
template<typename QType>
VTKM_EXEC_CONT_EXPORT
vtkm::Float64 RemainderQuotient(vtkm::Float64 numerator,
vtkm::Float64 denominator,
QType &quotient)
{
#ifdef VTKM_USE_BOOST_MATH
quotient = static_cast<QType>(boost::math::round(numerator/denominator));
return vtkm::Remainder(numerator, denominator);
#else
int iQuotient;
vtkm::Float64 result =
VTKM_SYS_MATH_FUNCTION_64(remquo)(numerator, denominator, &iQuotient);
quotient = iQuotient;
return result;
#endif
}
/// Gets the integral and fractional parts of \c x. The return value is the
/// fractional part and \c integral is set to the integral part.
///
VTKM_EXEC_CONT_EXPORT
vtkm::Float32 ModF(vtkm::Float32 x, vtkm::Float32 &integral)
{
return VTKM_SYS_MATH_FUNCTION_32(modf)(x, &integral);
}
VTKM_EXEC_CONT_EXPORT
vtkm::Float64 ModF(vtkm::Float64 x, vtkm::Float64 &integral)
{
return VTKM_SYS_MATH_FUNCTION_64(modf)(x, &integral);
}
//-----------------------------------------------------------------------------
/// Round \p x to the smallest integer value not less than x.
///
@ -1763,6 +1680,99 @@ vtkm::Vec<T,2> Round(const vtkm::Vec<T,2> &x) {
vtkm::Round(x[1]));
}
//-----------------------------------------------------------------------------
/// Computes the remainder on division of 2 floating point numbers. The return
/// value is \p numerator - n \p denominator, where n is the quotient of \p
/// numerator divided by \p denominator rounded towards zero to an integer. For
/// example, <tt>FMod(6.5, 2.3)</tt> returns 1.9, which is 6.5 - 2*2.3.
///
VTKM_EXEC_CONT_EXPORT
vtkm::Float32 FMod(vtkm::Float32 x, vtkm::Float32 y) {
return VTKM_SYS_MATH_FUNCTION_32(fmod)(x,y);
}
VTKM_EXEC_CONT_EXPORT
vtkm::Float64 FMod(vtkm::Float64 x, vtkm::Float64 y) {
return VTKM_SYS_MATH_FUNCTION_64(fmod)(x,y);
}
/// Computes the remainder on division of 2 floating point numbers. The return
/// value is \p numerator - n \p denominator, where n is the quotient of \p
/// numerator divided by \p denominator rounded towards the nearest integer
/// (instead of toward zero like FMod). For example, <tt>FMod(6.5, 2.3)</tt>
/// returns -0.4, which is 6.5 - 3*2.3.
///
#ifdef VTKM_MSVC
template<typename T>
VTKM_EXEC_CONT_EXPORT
T Remainder(T numerator, T denominator)
{
T quotient = vtkm::Round(numerator/denominator);
return numerator - quotient*denominator;
}
#else // !VTKM_MSVC
VTKM_EXEC_CONT_EXPORT
vtkm::Float32 Remainder(vtkm::Float32 x, vtkm::Float32 y) {
return VTKM_SYS_MATH_FUNCTION_32(remainder)(x,y);
}
VTKM_EXEC_CONT_EXPORT
vtkm::Float64 Remainder(vtkm::Float64 x, vtkm::Float64 y) {
return VTKM_SYS_MATH_FUNCTION_64(remainder)(x,y);
}
#endif // !VTKM_MSVC
/// Returns the remainder on division of 2 floating point numbers just like
/// Remainder. In addition, this function also returns the \c quotient used to
/// get that remainder.
///
template<typename QType>
VTKM_EXEC_CONT_EXPORT
vtkm::Float32 RemainderQuotient(vtkm::Float32 numerator,
vtkm::Float32 denominator,
QType &quotient)
{
#ifdef VTKM_USE_BOOST_MATH
quotient = static_cast<QType>(boost::math::round(numerator/denominator));
return vtkm::Remainder(numerator, denominator);
#else
int iQuotient;
vtkm::Float32 result =
VTKM_SYS_MATH_FUNCTION_32(remquo)(numerator, denominator, &iQuotient);
quotient = iQuotient;
return result;
#endif
}
template<typename QType>
VTKM_EXEC_CONT_EXPORT
vtkm::Float64 RemainderQuotient(vtkm::Float64 numerator,
vtkm::Float64 denominator,
QType &quotient)
{
#ifdef VTKM_USE_BOOST_MATH
quotient = static_cast<QType>(boost::math::round(numerator/denominator));
return vtkm::Remainder(numerator, denominator);
#else
int iQuotient;
vtkm::Float64 result =
VTKM_SYS_MATH_FUNCTION_64(remquo)(numerator, denominator, &iQuotient);
quotient = iQuotient;
return result;
#endif
}
/// Gets the integral and fractional parts of \c x. The return value is the
/// fractional part and \c integral is set to the integral part.
///
VTKM_EXEC_CONT_EXPORT
vtkm::Float32 ModF(vtkm::Float32 x, vtkm::Float32 &integral)
{
return VTKM_SYS_MATH_FUNCTION_32(modf)(x, &integral);
}
VTKM_EXEC_CONT_EXPORT
vtkm::Float64 ModF(vtkm::Float64 x, vtkm::Float64 &integral)
{
return VTKM_SYS_MATH_FUNCTION_64(modf)(x, &integral);
}
//-----------------------------------------------------------------------------
/// Return the absolute value of \x. That is, return \p x if it is positive or
/// \p -x if it is negative.

@ -365,14 +365,14 @@ VTKM_EXEC_CONT_EXPORT
vtkm::Float32 Log2(vtkm::Float32 x) {
//windows and boost don't provide log2
//0.6931471805599453 is the constant value of log(2)
const vtkm::Float32 log2v(0.6931471805599453);
const vtkm::Float32 log2v = 0.6931471805599453f;
return vtkm::Log(x)/log2v;
}
VTKM_EXEC_CONT_EXPORT
vtkm::Float64 Log2(vtkm::Float64 x) {
//windows and boost don't provide log2
//0.6931471805599453 is the constant value of log(2)
const vtkm::Float64 log2v(0.6931471805599453);
const vtkm::Float64 log2v = 0.6931471805599453;
return vtkm::Log(x)/log2v;
}
#else // !VTKM_USE_BOOST_MATH
@ -668,6 +668,26 @@ bool IsFinite(T x)
return (isfinite(x) != 0);
}
//-----------------------------------------------------------------------------
/// Round \p x to the smallest integer value not less than x.
///
$unary_math_function('Ceil', 'ceil')\
/// Round \p x to the largest integer value not greater than x.
///
$unary_math_function('Floor', 'floor')\
/// Round \p x to the nearest integral value.
///
#ifdef VTKM_USE_BOOST_MATH
$unary_template_function_no_vec('Round', 'boost::math::round(x)')\
$#
#else // !VTKM_USE_BOOST_MATH
$unary_math_function_no_vec('Round', 'round')\
$#
#endif // !VTKM_USE_BOOST_MATH
$unary_Vec_function('Round')\
//-----------------------------------------------------------------------------
/// Computes the remainder on division of 2 floating point numbers. The return
/// value is \p numerator - n \p denominator, where n is the quotient of \p
@ -682,7 +702,18 @@ $binary_math_function('FMod', 'fmod')\
/// (instead of toward zero like FMod). For example, <tt>FMod(6.5, 2.3)</tt>
/// returns -0.4, which is 6.5 - 3*2.3.
///
#ifdef VTKM_MSVC
template<typename T>
VTKM_EXEC_CONT_EXPORT
T Remainder(T numerator, T denominator)
{
T quotient = vtkm::Round(numerator/denominator);
return numerator - quotient*denominator;
}
#else // !VTKM_MSVC
$binary_math_function('Remainder', 'remainder')\
$#
#endif // !VTKM_MSVC
/// Returns the remainder on division of 2 floating point numbers just like
/// Remainder. In addition, this function also returns the \c quotient used to
@ -737,26 +768,6 @@ vtkm::Float64 ModF(vtkm::Float64 x, vtkm::Float64 &integral)
return VTKM_SYS_MATH_FUNCTION_64(modf)(x, &integral);
}
//-----------------------------------------------------------------------------
/// Round \p x to the smallest integer value not less than x.
///
$unary_math_function('Ceil', 'ceil')\
/// Round \p x to the largest integer value not greater than x.
///
$unary_math_function('Floor', 'floor')\
/// Round \p x to the nearest integral value.
///
#ifdef VTKM_USE_BOOST_MATH
$unary_template_function_no_vec('Round', 'boost::math::round(x)')\
$#
#else // !VTKM_USE_BOOST_MATH
$unary_math_function_no_vec('Round', 'round')\
$#
#endif // !VTKM_USE_BOOST_MATH
$unary_Vec_function('Round')\
//-----------------------------------------------------------------------------
/// Return the absolute value of \x. That is, return \p x if it is positive or
/// \p -x if it is negative.