Math.h 71.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
//=============================================================================
//
//  Copyright (c) Kitware, Inc.
//  All rights reserved.
//  See LICENSE.txt for details.
//
//  This software is distributed WITHOUT ANY WARRANTY; without even
//  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
//  PURPOSE.  See the above copyright notice for more information.
//
Kenneth Moreland's avatar
Kenneth Moreland committed
11
//  Copyright 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
12 13 14
//  Copyright 2015 UT-Battelle, LLC.
//  Copyright 2015 Los Alamos National Security.
//
Kenneth Moreland's avatar
Kenneth Moreland committed
15
//  Under the terms of Contract DE-NA0003525 with NTESS,
16 17 18 19 20 21 22
//  the U.S. Government retains certain rights in this software.
//  Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
//  Laboratory (LANL), the U.S. Government retains certain rights in
//  this software.
//
//=============================================================================
// **** DO NOT EDIT THIS FILE!!! ****
23
// This file is automatically generated by Math.h.in
24 25 26 27

#ifndef vtk_m_Math_h
#define vtk_m_Math_h

28
#include <vtkm/TypeTraits.h>
29
#include <vtkm/Types.h>
30
#include <vtkm/VecTraits.h>
31 32

#ifndef VTKM_CUDA
33
#include <cmath>
34
#include <limits.h>
35
#include <math.h>
36
#include <stdlib.h>
37
#endif // !VTKM_CUDA
38

39
#if !defined(__CUDA_ARCH__)
40
#define VTKM_USE_STL
41 42 43
#include <algorithm>
#endif

Kenneth Moreland's avatar
Kenneth Moreland committed
44
#if defined(VTKM_MSVC) && !defined(VTKM_CUDA)
45
#include <math.h>
46 47
#endif

48
#define VTKM_CUDA_MATH_FUNCTION_32(func) func##f
49
#define VTKM_CUDA_MATH_FUNCTION_64(func) func
50

51 52
namespace vtkm
{
53

Kenneth Moreland's avatar
Kenneth Moreland committed
54
//-----------------------------------------------------------------------------
Kenneth Moreland's avatar
Kenneth Moreland committed
55 56
/// Returns the constant 2 times Pi.
///
57
static inline VTKM_EXEC_CONT vtkm::Float64 TwoPi()
Kenneth Moreland's avatar
Kenneth Moreland committed
58 59 60 61
{
  return 6.28318530717958647692528676655900576;
}

Kenneth Moreland's avatar
Kenneth Moreland committed
62 63
/// Returns the constant Pi.
///
64
static inline VTKM_EXEC_CONT vtkm::Float64 Pi()
Kenneth Moreland's avatar
Kenneth Moreland committed
65 66 67 68
{
  return 3.14159265358979323846264338327950288;
}

Kenneth Moreland's avatar
Kenneth Moreland committed
69 70
/// Returns the constant Pi halves.
///
71
static inline VTKM_EXEC_CONT vtkm::Float64 Pi_2()
Kenneth Moreland's avatar
Kenneth Moreland committed
72 73 74 75 76
{
  return 1.57079632679489661923132169163975144;
}
/// Returns the constant Pi thirds.
///
77
static inline VTKM_EXEC_CONT vtkm::Float64 Pi_3()
Kenneth Moreland's avatar
Kenneth Moreland committed
78 79 80 81 82 83
{
  return 1.04719755119659774615421446109316762;
}

/// Returns the constant Pi fourths.
///
84
static inline VTKM_EXEC_CONT vtkm::Float64 Pi_4()
Kenneth Moreland's avatar
Kenneth Moreland committed
85 86 87 88
{
  return 0.78539816339744830961566084581987572;
}

89 90 91 92 93
namespace detail
{
template <typename T>
struct FloatingPointReturnType
{
94 95 96 97 98 99 100 101
  using ctype = typename vtkm::VecTraits<T>::ComponentType;
  using representable_as_float_type =
    std::integral_constant<bool,
                           ((sizeof(ctype) < sizeof(float)) ||
                            std::is_same<ctype, vtkm::Float32>::value)>;
  using Type = typename std::conditional<representable_as_float_type::value,
                                         vtkm::Float32,
                                         vtkm::Float64>::type;
102
};
103
} // namespace detail
104

Kenneth Moreland's avatar
Kenneth Moreland committed
105 106
/// Compute the sine of \p x.
///
107 108

inline VTKM_EXEC_CONT vtkm::Float32 Sin(vtkm::Float32 x)
109
{
110 111 112 113 114
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(sin)(x);
#else
  return std::sin(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
115
}
116 117

inline VTKM_EXEC_CONT vtkm::Float64 Sin(vtkm::Float64 x)
118
{
119 120 121 122 123
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(sin)(x);
#else
  return std::sin(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
124
}
125 126 127 128 129 130
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Sin(const T& x)
{
  using RT = typename detail::FloatingPointReturnType<T>::Type;
  return vtkm::Sin(static_cast<RT>(x));
}
131 132 133 134 135
template <typename T, vtkm::IdComponent N>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> Sin(
  const vtkm::Vec<T, N>& x)
{
  vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> result;
Kenneth Moreland's avatar
Kenneth Moreland committed
136 137 138 139 140 141
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::Sin(x[index]);
  }
  return result;
}
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4> Sin(
  const vtkm::Vec<T, 4>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4>(
    vtkm::Sin(x[0]), vtkm::Sin(x[1]), vtkm::Sin(x[2]), vtkm::Sin(x[3]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3> Sin(
  const vtkm::Vec<T, 3>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3>(
    vtkm::Sin(x[0]), vtkm::Sin(x[1]), vtkm::Sin(x[2]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2> Sin(
  const vtkm::Vec<T, 2>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2>(vtkm::Sin(x[0]),
                                                                         vtkm::Sin(x[1]));
Kenneth Moreland's avatar
Kenneth Moreland committed
162 163 164 165
}

/// Compute the cosine of \p x.
///
166 167

inline VTKM_EXEC_CONT vtkm::Float32 Cos(vtkm::Float32 x)
168
{
169 170 171 172 173
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(cos)(x);
#else
  return std::cos(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
174
}
175 176

inline VTKM_EXEC_CONT vtkm::Float64 Cos(vtkm::Float64 x)
177
{
178 179 180 181 182
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(cos)(x);
#else
  return std::cos(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
183
}
184 185 186 187 188 189
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Cos(const T& x)
{
  using RT = typename detail::FloatingPointReturnType<T>::Type;
  return vtkm::Cos(static_cast<RT>(x));
}
190 191 192 193 194
template <typename T, vtkm::IdComponent N>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> Cos(
  const vtkm::Vec<T, N>& x)
{
  vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> result;
Kenneth Moreland's avatar
Kenneth Moreland committed
195 196 197 198 199 200
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::Cos(x[index]);
  }
  return result;
}
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4> Cos(
  const vtkm::Vec<T, 4>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4>(
    vtkm::Cos(x[0]), vtkm::Cos(x[1]), vtkm::Cos(x[2]), vtkm::Cos(x[3]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3> Cos(
  const vtkm::Vec<T, 3>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3>(
    vtkm::Cos(x[0]), vtkm::Cos(x[1]), vtkm::Cos(x[2]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2> Cos(
  const vtkm::Vec<T, 2>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2>(vtkm::Cos(x[0]),
                                                                         vtkm::Cos(x[1]));
Kenneth Moreland's avatar
Kenneth Moreland committed
221 222 223 224
}

/// Compute the tangent of \p x.
///
225 226

inline VTKM_EXEC_CONT vtkm::Float32 Tan(vtkm::Float32 x)
227
{
228 229 230 231 232
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(tan)(x);
#else
  return std::tan(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
233
}
234 235

inline VTKM_EXEC_CONT vtkm::Float64 Tan(vtkm::Float64 x)
236
{
237 238 239 240 241
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(tan)(x);
#else
  return std::tan(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
242
}
243 244 245 246 247 248
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Tan(const T& x)
{
  using RT = typename detail::FloatingPointReturnType<T>::Type;
  return vtkm::Tan(static_cast<RT>(x));
}
249 250 251 252 253
template <typename T, vtkm::IdComponent N>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> Tan(
  const vtkm::Vec<T, N>& x)
{
  vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> result;
Kenneth Moreland's avatar
Kenneth Moreland committed
254 255 256 257 258 259
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::Tan(x[index]);
  }
  return result;
}
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4> Tan(
  const vtkm::Vec<T, 4>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4>(
    vtkm::Tan(x[0]), vtkm::Tan(x[1]), vtkm::Tan(x[2]), vtkm::Tan(x[3]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3> Tan(
  const vtkm::Vec<T, 3>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3>(
    vtkm::Tan(x[0]), vtkm::Tan(x[1]), vtkm::Tan(x[2]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2> Tan(
  const vtkm::Vec<T, 2>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2>(vtkm::Tan(x[0]),
                                                                         vtkm::Tan(x[1]));
Kenneth Moreland's avatar
Kenneth Moreland committed
280 281 282 283
}

/// Compute the arc sine of \p x.
///
284 285

inline VTKM_EXEC_CONT vtkm::Float32 ASin(vtkm::Float32 x)
286
{
287 288 289 290 291
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(asin)(x);
#else
  return std::asin(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
292
}
293 294

inline VTKM_EXEC_CONT vtkm::Float64 ASin(vtkm::Float64 x)
295
{
296 297 298 299 300
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(asin)(x);
#else
  return std::asin(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
301
}
302 303 304 305 306 307
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type ASin(const T& x)
{
  using RT = typename detail::FloatingPointReturnType<T>::Type;
  return vtkm::ASin(static_cast<RT>(x));
}
308 309 310 311 312
template <typename T, vtkm::IdComponent N>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> ASin(
  const vtkm::Vec<T, N>& x)
{
  vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> result;
Kenneth Moreland's avatar
Kenneth Moreland committed
313 314 315 316 317 318
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::ASin(x[index]);
  }
  return result;
}
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4> ASin(
  const vtkm::Vec<T, 4>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4>(
    vtkm::ASin(x[0]), vtkm::ASin(x[1]), vtkm::ASin(x[2]), vtkm::ASin(x[3]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3> ASin(
  const vtkm::Vec<T, 3>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3>(
    vtkm::ASin(x[0]), vtkm::ASin(x[1]), vtkm::ASin(x[2]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2> ASin(
  const vtkm::Vec<T, 2>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2>(vtkm::ASin(x[0]),
                                                                         vtkm::ASin(x[1]));
Kenneth Moreland's avatar
Kenneth Moreland committed
339 340 341 342
}

/// Compute the arc cosine of \p x.
///
343 344

inline VTKM_EXEC_CONT vtkm::Float32 ACos(vtkm::Float32 x)
345
{
346 347 348 349 350
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(acos)(x);
#else
  return std::acos(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
351
}
352 353

inline VTKM_EXEC_CONT vtkm::Float64 ACos(vtkm::Float64 x)
354
{
355 356 357 358 359
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(acos)(x);
#else
  return std::acos(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
360
}
361 362 363 364 365 366
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type ACos(const T& x)
{
  using RT = typename detail::FloatingPointReturnType<T>::Type;
  return vtkm::ACos(static_cast<RT>(x));
}
367 368 369 370 371
template <typename T, vtkm::IdComponent N>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> ACos(
  const vtkm::Vec<T, N>& x)
{
  vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> result;
Kenneth Moreland's avatar
Kenneth Moreland committed
372 373 374 375 376 377
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::ACos(x[index]);
  }
  return result;
}
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4> ACos(
  const vtkm::Vec<T, 4>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4>(
    vtkm::ACos(x[0]), vtkm::ACos(x[1]), vtkm::ACos(x[2]), vtkm::ACos(x[3]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3> ACos(
  const vtkm::Vec<T, 3>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3>(
    vtkm::ACos(x[0]), vtkm::ACos(x[1]), vtkm::ACos(x[2]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2> ACos(
  const vtkm::Vec<T, 2>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2>(vtkm::ACos(x[0]),
                                                                         vtkm::ACos(x[1]));
Kenneth Moreland's avatar
Kenneth Moreland committed
398 399 400 401
}

/// Compute the arc tangent of \p x.
///
402 403

inline VTKM_EXEC_CONT vtkm::Float32 ATan(vtkm::Float32 x)
404
{
405 406 407 408 409
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(atan)(x);
#else
  return std::atan(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
410
}
411 412

inline VTKM_EXEC_CONT vtkm::Float64 ATan(vtkm::Float64 x)
413
{
414 415 416 417 418
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(atan)(x);
#else
  return std::atan(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
419
}
420 421 422 423 424 425
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type ATan(const T& x)
{
  using RT = typename detail::FloatingPointReturnType<T>::Type;
  return vtkm::ATan(static_cast<RT>(x));
}
426 427 428 429 430
template <typename T, vtkm::IdComponent N>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> ATan(
  const vtkm::Vec<T, N>& x)
{
  vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> result;
Kenneth Moreland's avatar
Kenneth Moreland committed
431 432 433 434 435 436
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::ATan(x[index]);
  }
  return result;
}
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4> ATan(
  const vtkm::Vec<T, 4>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4>(
    vtkm::ATan(x[0]), vtkm::ATan(x[1]), vtkm::ATan(x[2]), vtkm::ATan(x[3]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3> ATan(
  const vtkm::Vec<T, 3>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3>(
    vtkm::ATan(x[0]), vtkm::ATan(x[1]), vtkm::ATan(x[2]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2> ATan(
  const vtkm::Vec<T, 2>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2>(vtkm::ATan(x[0]),
                                                                         vtkm::ATan(x[1]));
Kenneth Moreland's avatar
Kenneth Moreland committed
457 458 459 460 461
}

/// Compute the arc tangent of \p x / \p y using the signs of both arguments
/// to determine the quadrant of the return value.
///
462 463
static inline VTKM_EXEC_CONT vtkm::Float32 ATan2(vtkm::Float32 x, vtkm::Float32 y)
{
464
#ifdef VTKM_CUDA
465
  return VTKM_CUDA_MATH_FUNCTION_32(atan2)(x, y);
466
#else
467
  return std::atan2(x, y);
468
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
469
}
470 471
static inline VTKM_EXEC_CONT vtkm::Float64 ATan2(vtkm::Float64 x, vtkm::Float64 y)
{
472
#ifdef VTKM_CUDA
473
  return VTKM_CUDA_MATH_FUNCTION_64(atan2)(x, y);
474
#else
475
  return std::atan2(x, y);
476
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
477 478 479 480
}

/// Compute the hyperbolic sine of \p x.
///
481 482

inline VTKM_EXEC_CONT vtkm::Float32 SinH(vtkm::Float32 x)
483
{
484 485 486 487 488
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(sinh)(x);
#else
  return std::sinh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
489
}
490 491

inline VTKM_EXEC_CONT vtkm::Float64 SinH(vtkm::Float64 x)
492
{
493 494 495 496 497
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(sinh)(x);
#else
  return std::sinh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
498
}
499 500 501 502 503 504
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type SinH(const T& x)
{
  using RT = typename detail::FloatingPointReturnType<T>::Type;
  return vtkm::SinH(static_cast<RT>(x));
}
505 506 507 508 509
template <typename T, vtkm::IdComponent N>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> SinH(
  const vtkm::Vec<T, N>& x)
{
  vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> result;
Kenneth Moreland's avatar
Kenneth Moreland committed
510 511 512 513 514 515
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::SinH(x[index]);
  }
  return result;
}
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4> SinH(
  const vtkm::Vec<T, 4>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4>(
    vtkm::SinH(x[0]), vtkm::SinH(x[1]), vtkm::SinH(x[2]), vtkm::SinH(x[3]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3> SinH(
  const vtkm::Vec<T, 3>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3>(
    vtkm::SinH(x[0]), vtkm::SinH(x[1]), vtkm::SinH(x[2]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2> SinH(
  const vtkm::Vec<T, 2>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2>(vtkm::SinH(x[0]),
                                                                         vtkm::SinH(x[1]));
Kenneth Moreland's avatar
Kenneth Moreland committed
536 537 538 539
}

/// Compute the hyperbolic cosine of \p x.
///
540 541

inline VTKM_EXEC_CONT vtkm::Float32 CosH(vtkm::Float32 x)
542
{
543 544 545 546 547
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(cosh)(x);
#else
  return std::cosh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
548
}
549 550

inline VTKM_EXEC_CONT vtkm::Float64 CosH(vtkm::Float64 x)
551
{
552 553 554 555 556
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(cosh)(x);
#else
  return std::cosh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
557
}
558 559 560 561 562 563
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type CosH(const T& x)
{
  using RT = typename detail::FloatingPointReturnType<T>::Type;
  return vtkm::CosH(static_cast<RT>(x));
}
564 565 566 567 568
template <typename T, vtkm::IdComponent N>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> CosH(
  const vtkm::Vec<T, N>& x)
{
  vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> result;
Kenneth Moreland's avatar
Kenneth Moreland committed
569 570 571 572 573 574
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::CosH(x[index]);
  }
  return result;
}
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4> CosH(
  const vtkm::Vec<T, 4>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4>(
    vtkm::CosH(x[0]), vtkm::CosH(x[1]), vtkm::CosH(x[2]), vtkm::CosH(x[3]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3> CosH(
  const vtkm::Vec<T, 3>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3>(
    vtkm::CosH(x[0]), vtkm::CosH(x[1]), vtkm::CosH(x[2]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2> CosH(
  const vtkm::Vec<T, 2>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2>(vtkm::CosH(x[0]),
                                                                         vtkm::CosH(x[1]));
Kenneth Moreland's avatar
Kenneth Moreland committed
595 596 597 598
}

/// Compute the hyperbolic tangent of \p x.
///
599 600

inline VTKM_EXEC_CONT vtkm::Float32 TanH(vtkm::Float32 x)
601
{
602 603 604 605 606
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(tanh)(x);
#else
  return std::tanh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
607
}
608 609

inline VTKM_EXEC_CONT vtkm::Float64 TanH(vtkm::Float64 x)
610
{
611 612 613 614 615
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(tanh)(x);
#else
  return std::tanh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
616
}
617 618 619 620 621 622
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type TanH(const T& x)
{
  using RT = typename detail::FloatingPointReturnType<T>::Type;
  return vtkm::TanH(static_cast<RT>(x));
}
623 624 625 626 627
template <typename T, vtkm::IdComponent N>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> TanH(
  const vtkm::Vec<T, N>& x)
{
  vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> result;
Kenneth Moreland's avatar
Kenneth Moreland committed
628 629 630 631 632 633
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::TanH(x[index]);
  }
  return result;
}
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4> TanH(
  const vtkm::Vec<T, 4>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4>(
    vtkm::TanH(x[0]), vtkm::TanH(x[1]), vtkm::TanH(x[2]), vtkm::TanH(x[3]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3> TanH(
  const vtkm::Vec<T, 3>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3>(
    vtkm::TanH(x[0]), vtkm::TanH(x[1]), vtkm::TanH(x[2]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2> TanH(
  const vtkm::Vec<T, 2>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2>(vtkm::TanH(x[0]),
                                                                         vtkm::TanH(x[1]));
Kenneth Moreland's avatar
Kenneth Moreland committed
654 655 656 657
}

/// Compute the hyperbolic arc sine of \p x.
///
658 659

inline VTKM_EXEC_CONT vtkm::Float32 ASinH(vtkm::Float32 x)
660
{
661 662 663 664 665
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(asinh)(x);
#else
  return std::asinh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
666
}
667 668

inline VTKM_EXEC_CONT vtkm::Float64 ASinH(vtkm::Float64 x)
669
{
670 671 672 673 674
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(asinh)(x);
#else
  return std::asinh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
675
}
676 677 678 679 680 681
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type ASinH(const T& x)
{
  using RT = typename detail::FloatingPointReturnType<T>::Type;
  return vtkm::ASinH(static_cast<RT>(x));
}
682 683 684 685 686
template <typename T, vtkm::IdComponent N>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> ASinH(
  const vtkm::Vec<T, N>& x)
{
  vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> result;
Kenneth Moreland's avatar
Kenneth Moreland committed
687 688 689 690 691 692
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::ASinH(x[index]);
  }
  return result;
}
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4> ASinH(
  const vtkm::Vec<T, 4>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4>(
    vtkm::ASinH(x[0]), vtkm::ASinH(x[1]), vtkm::ASinH(x[2]), vtkm::ASinH(x[3]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3> ASinH(
  const vtkm::Vec<T, 3>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3>(
    vtkm::ASinH(x[0]), vtkm::ASinH(x[1]), vtkm::ASinH(x[2]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2> ASinH(
  const vtkm::Vec<T, 2>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2>(vtkm::ASinH(x[0]),
                                                                         vtkm::ASinH(x[1]));
Kenneth Moreland's avatar
Kenneth Moreland committed
713 714 715 716
}

/// Compute the hyperbolic arc cosine of \p x.
///
717 718

inline VTKM_EXEC_CONT vtkm::Float32 ACosH(vtkm::Float32 x)
719
{
720 721 722 723 724
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(acosh)(x);
#else
  return std::acosh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
725
}
726 727

inline VTKM_EXEC_CONT vtkm::Float64 ACosH(vtkm::Float64 x)
728
{
729 730 731 732 733
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(acosh)(x);
#else
  return std::acosh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
734
}
735 736 737 738 739 740
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type ACosH(const T& x)
{
  using RT = typename detail::FloatingPointReturnType<T>::Type;
  return vtkm::ACosH(static_cast<RT>(x));
}
741 742 743 744 745
template <typename T, vtkm::IdComponent N>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> ACosH(
  const vtkm::Vec<T, N>& x)
{
  vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> result;
Kenneth Moreland's avatar
Kenneth Moreland committed
746 747 748 749 750 751
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::ACosH(x[index]);
  }
  return result;
}
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4> ACosH(
  const vtkm::Vec<T, 4>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4>(
    vtkm::ACosH(x[0]), vtkm::ACosH(x[1]), vtkm::ACosH(x[2]), vtkm::ACosH(x[3]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3> ACosH(
  const vtkm::Vec<T, 3>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3>(
    vtkm::ACosH(x[0]), vtkm::ACosH(x[1]), vtkm::ACosH(x[2]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2> ACosH(
  const vtkm::Vec<T, 2>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2>(vtkm::ACosH(x[0]),
                                                                         vtkm::ACosH(x[1]));
Kenneth Moreland's avatar
Kenneth Moreland committed
772 773 774 775
}

/// Compute the hyperbolic arc tangent of \p x.
///
776 777

inline VTKM_EXEC_CONT vtkm::Float32 ATanH(vtkm::Float32 x)
778
{
779 780 781 782 783
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(atanh)(x);
#else
  return std::atanh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
784
}
785 786

inline VTKM_EXEC_CONT vtkm::Float64 ATanH(vtkm::Float64 x)
787
{
788 789 790 791 792
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(atanh)(x);
#else
  return std::atanh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
793
}
794 795 796 797 798 799
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type ATanH(const T& x)
{
  using RT = typename detail::FloatingPointReturnType<T>::Type;
  return vtkm::ATanH(static_cast<RT>(x));
}
800 801 802 803 804
template <typename T, vtkm::IdComponent N>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> ATanH(
  const vtkm::Vec<T, N>& x)
{
  vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> result;
Kenneth Moreland's avatar
Kenneth Moreland committed
805 806 807 808 809 810
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::ATanH(x[index]);
  }
  return result;
}
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4> ATanH(
  const vtkm::Vec<T, 4>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4>(
    vtkm::ATanH(x[0]), vtkm::ATanH(x[1]), vtkm::ATanH(x[2]), vtkm::ATanH(x[3]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3> ATanH(
  const vtkm::Vec<T, 3>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3>(
    vtkm::ATanH(x[0]), vtkm::ATanH(x[1]), vtkm::ATanH(x[2]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2> ATanH(
  const vtkm::Vec<T, 2>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2>(vtkm::ATanH(x[0]),
                                                                         vtkm::ATanH(x[1]));
Kenneth Moreland's avatar
Kenneth Moreland committed
831 832
}

833
//-----------------------------------------------------------------------------
834 835
/// Computes \p x raised to the power of \p y.
///
836 837
static inline VTKM_EXEC_CONT vtkm::Float32 Pow(vtkm::Float32 x, vtkm::Float32 y)
{
838
#ifdef VTKM_CUDA
839
  return VTKM_CUDA_MATH_FUNCTION_32(pow)(x, y);
840
#else
841
  return std::pow(x, y);
842
#endif
843
}
844 845
static inline VTKM_EXEC_CONT vtkm::Float64 Pow(vtkm::Float64 x, vtkm::Float64 y)
{
846
#ifdef VTKM_CUDA
847
  return VTKM_CUDA_MATH_FUNCTION_64(pow)(x, y);
848
#else
849
  return std::pow(x, y);
850
#endif
851 852
}

853 854
/// Compute the square root of \p x.
///
855 856

inline VTKM_EXEC_CONT vtkm::Float32 Sqrt(vtkm::Float32 x)
857
{
858 859 860 861 862
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(sqrt)(x);
#else
  return std::sqrt(x);
#endif
863
}
864 865

inline VTKM_EXEC_CONT vtkm::Float64 Sqrt(vtkm::Float64 x)
866
{
867 868 869 870 871
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(sqrt)(x);
#else
  return std::sqrt(x);
#endif
872
}
873 874 875 876 877 878
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Sqrt(const T& x)
{
  using RT = typename detail::FloatingPointReturnType<T>::Type;
  return vtkm::Sqrt(static_cast<RT>(x));
}
879 880 881 882 883
template <typename T, vtkm::IdComponent N>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> Sqrt(
  const vtkm::Vec<T, N>& x)
{
  vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> result;
884 885 886 887 888 889
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::Sqrt(x[index]);
  }
  return result;
}
890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4> Sqrt(
  const vtkm::Vec<T, 4>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4>(
    vtkm::Sqrt(x[0]), vtkm::Sqrt(x[1]), vtkm::Sqrt(x[2]), vtkm::Sqrt(x[3]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3> Sqrt(
  const vtkm::Vec<T, 3>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3>(
    vtkm::Sqrt(x[0]), vtkm::Sqrt(x[1]), vtkm::Sqrt(x[2]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2> Sqrt(
  const vtkm::Vec<T, 2>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2>(vtkm::Sqrt(x[0]),
                                                                         vtkm::Sqrt(x[1]));
910 911
}

912 913 914 915 916 917
/// Compute the reciprocal square root of \p x. The result of this function is
/// equivalent to <tt>1/Sqrt(x)</tt>. However, on some devices it is faster to
/// compute the reciprocal square root than the regular square root. Thus, you
/// should use this function whenever dividing by the square root.
///
#ifdef VTKM_CUDA
918 919
static inline VTKM_EXEC_CONT vtkm::Float32 RSqrt(vtkm::Float32 x)
{
920
  return rsqrtf(x);
921
}
922 923
static inline VTKM_EXEC_CONT vtkm::Float64 RSqrt(vtkm::Float64 x)
{
924
  return rsqrt(x);
925
}
926 927 928
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Float64 RSqrt(T x)
{
929 930
  return rsqrt(static_cast<vtkm::Float64>(x));
}
931 932 933 934
#else  // !VTKM_CUDA
static inline VTKM_EXEC_CONT vtkm::Float32 RSqrt(vtkm::Float32 x)
{
  return 1 / vtkm::Sqrt(x);
935
}
936 937 938
static inline VTKM_EXEC_CONT vtkm::Float64 RSqrt(vtkm::Float64 x)
{
  return 1 / vtkm::Sqrt(x);
939
}
940 941 942 943
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Float64 RSqrt(T x)
{
  return 1 / static_cast<vtkm::Float64>(x);
944
}
945
#endif // !VTKM_CUDA
946

947 948 949 950 951
template <typename T, vtkm::IdComponent N>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> RSqrt(
  const vtkm::Vec<T, N>& x)
{
  vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> result;
952 953 954 955 956 957
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::RSqrt(x[index]);
  }
  return result;
}
958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4> RSqrt(
  const vtkm::Vec<T, 4>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4>(
    vtkm::RSqrt(x[0]), vtkm::RSqrt(x[1]), vtkm::RSqrt(x[2]), vtkm::RSqrt(x[3]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3> RSqrt(
  const vtkm::Vec<T, 3>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3>(
    vtkm::RSqrt(x[0]), vtkm::RSqrt(x[1]), vtkm::RSqrt(x[2]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2> RSqrt(
  const vtkm::Vec<T, 2>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2>(vtkm::RSqrt(x[0]),
                                                                         vtkm::RSqrt(x[1]));
978 979 980 981
}

/// Compute the cube root of \p x.
///
982 983

inline VTKM_EXEC_CONT vtkm::Float32 Cbrt(vtkm::Float32 x)
984
{
985 986 987 988 989
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(cbrt)(x);
#else
  return std::cbrt(x);
#endif
990
}
991 992

inline VTKM_EXEC_CONT vtkm::Float64 Cbrt(vtkm::Float64 x)
993
{
994 995 996 997 998
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(cbrt)(x);
#else
  return std::cbrt(x);
#endif
999
}
1000 1001 1002 1003 1004 1005
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Cbrt(const T& x)
{
  using RT = typename detail::FloatingPointReturnType<T>::Type;
  return vtkm::Cbrt(static_cast<RT>(x));
}
1006 1007 1008 1009 1010
template <typename T, vtkm::IdComponent N>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> Cbrt(
  const vtkm::Vec<T, N>& x)
{
  vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> result;
1011 1012 1013 1014 1015 1016
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::Cbrt(x[index]);
  }
  return result;
}
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4> Cbrt(
  const vtkm::Vec<T, 4>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4>(
    vtkm::Cbrt(x[0]), vtkm::Cbrt(x[1]), vtkm::Cbrt(x[2]), vtkm::Cbrt(x[3]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3> Cbrt(
  const vtkm::Vec<T, 3>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3>(
    vtkm::Cbrt(x[0]), vtkm::Cbrt(x[1]), vtkm::Cbrt(x[2]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2> Cbrt(
  const vtkm::Vec<T, 2>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2>(vtkm::Cbrt(x[0]),
                                                                         vtkm::Cbrt(x[1]));
1037 1038 1039 1040 1041 1042 1043 1044
}

/// Compute the reciprocal cube root of \p x. The result of this function is
/// equivalent to <tt>1/Cbrt(x)</tt>. However, on some devices it is faster to
/// compute the reciprocal cube root than the regular cube root. Thus, you
/// should use this function whenever dividing by the cube root.
///
#ifdef VTKM_CUDA
1045 1046
static inline VTKM_EXEC_CONT vtkm::Float32 RCbrt(vtkm::Float32 x)
{
1047
  return rcbrtf(x);
1048
}
1049 1050
static inline VTKM_EXEC_CONT vtkm::Float64 RCbrt(vtkm::Float64 x)
{
1051
  return rcbrt(x);
1052
}
1053 1054 1055
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Float64 RCbrt(T x)
{
Thomas Otahal's avatar