Math.h 75.1 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
namespace detail
{
91

92
93
94
95
96
97
98
template <typename T>
struct FloatingPointReturnCondition
  : std::enable_if<
      std::is_same<typename vtkm::VecTraits<T>::ComponentType, vtkm::Float32>::value ||
      std::is_same<typename vtkm::VecTraits<T>::ComponentType, const vtkm::Float32>::value>
{
};
99

100
101
102
template <typename T, typename = void>
struct FloatingPointReturnType
{
103
  using Type = vtkm::Float64;
104
};
105

106
107
108
template <typename T>
struct FloatingPointReturnType<T, typename FloatingPointReturnCondition<T>::type>
{
109
  using Type = vtkm::Float32;
110
};
111
} // namespace detail
112

Kenneth Moreland's avatar
Kenneth Moreland committed
113
114
/// Compute the sine of \p x.
///
115
116
117
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Sin(T x)
{
118
#ifdef VTKM_CUDA
119
  return VTKM_CUDA_MATH_FUNCTION_64(sin)(static_cast<vtkm::Float64>(x));
120
#else
121
  return std::sin(static_cast<vtkm::Float64>(x));
122
123
#endif
}
124
125
126
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float32>::Type Sin(vtkm::Float32 x)
{
127
128
129
130
131
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(sin)(x);
#else
  return std::sin(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
132
}
133
134
135
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float64>::Type Sin(vtkm::Float64 x)
{
136
137
138
139
140
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(sin)(x);
#else
  return std::sin(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
141
}
142
143
144
145
146
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
147
148
149
150
151
152
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::Sin(x[index]);
  }
  return result;
}
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
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
173
174
175
176
}

/// Compute the cosine of \p x.
///
177
178
179
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Cos(T x)
{
180
#ifdef VTKM_CUDA
181
  return VTKM_CUDA_MATH_FUNCTION_64(cos)(static_cast<vtkm::Float64>(x));
182
#else
183
  return std::cos(static_cast<vtkm::Float64>(x));
184
185
#endif
}
186
187
188
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float32>::Type Cos(vtkm::Float32 x)
{
189
190
191
192
193
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(cos)(x);
#else
  return std::cos(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
194
}
195
196
197
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float64>::Type Cos(vtkm::Float64 x)
{
198
199
200
201
202
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(cos)(x);
#else
  return std::cos(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
203
}
204
205
206
207
208
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
209
210
211
212
213
214
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::Cos(x[index]);
  }
  return result;
}
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
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
235
236
237
238
}

/// Compute the tangent of \p x.
///
239
240
241
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Tan(T x)
{
242
#ifdef VTKM_CUDA
243
  return VTKM_CUDA_MATH_FUNCTION_64(tan)(static_cast<vtkm::Float64>(x));
244
#else
245
  return std::tan(static_cast<vtkm::Float64>(x));
246
247
#endif
}
248
249
250
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float32>::Type Tan(vtkm::Float32 x)
{
251
252
253
254
255
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(tan)(x);
#else
  return std::tan(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
256
}
257
258
259
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float64>::Type Tan(vtkm::Float64 x)
{
260
261
262
263
264
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(tan)(x);
#else
  return std::tan(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
265
}
266
267
268
269
270
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
271
272
273
274
275
276
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::Tan(x[index]);
  }
  return result;
}
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
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
297
298
299
300
}

/// Compute the arc sine of \p x.
///
301
302
303
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type ASin(T x)
{
304
#ifdef VTKM_CUDA
305
  return VTKM_CUDA_MATH_FUNCTION_64(asin)(static_cast<vtkm::Float64>(x));
306
#else
307
  return std::asin(static_cast<vtkm::Float64>(x));
308
309
#endif
}
310
311
312
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float32>::Type ASin(vtkm::Float32 x)
{
313
314
315
316
317
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(asin)(x);
#else
  return std::asin(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
318
}
319
320
321
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float64>::Type ASin(vtkm::Float64 x)
{
322
323
324
325
326
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(asin)(x);
#else
  return std::asin(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
327
}
328
329
330
331
332
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
333
334
335
336
337
338
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::ASin(x[index]);
  }
  return result;
}
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
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
359
360
361
362
}

/// Compute the arc cosine of \p x.
///
363
364
365
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type ACos(T x)
{
366
#ifdef VTKM_CUDA
367
  return VTKM_CUDA_MATH_FUNCTION_64(acos)(static_cast<vtkm::Float64>(x));
368
#else
369
  return std::acos(static_cast<vtkm::Float64>(x));
370
371
#endif
}
372
373
374
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float32>::Type ACos(vtkm::Float32 x)
{
375
376
377
378
379
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(acos)(x);
#else
  return std::acos(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
380
}
381
382
383
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float64>::Type ACos(vtkm::Float64 x)
{
384
385
386
387
388
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(acos)(x);
#else
  return std::acos(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
389
}
390
391
392
393
394
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
395
396
397
398
399
400
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::ACos(x[index]);
  }
  return result;
}
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
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
421
422
423
424
}

/// Compute the arc tangent of \p x.
///
425
426
427
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type ATan(T x)
{
428
#ifdef VTKM_CUDA
429
  return VTKM_CUDA_MATH_FUNCTION_64(atan)(static_cast<vtkm::Float64>(x));
430
#else
431
  return std::atan(static_cast<vtkm::Float64>(x));
432
433
#endif
}
434
435
436
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float32>::Type ATan(vtkm::Float32 x)
{
437
438
439
440
441
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(atan)(x);
#else
  return std::atan(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
442
}
443
444
445
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float64>::Type ATan(vtkm::Float64 x)
{
446
447
448
449
450
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(atan)(x);
#else
  return std::atan(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
451
}
452
453
454
455
456
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
457
458
459
460
461
462
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::ATan(x[index]);
  }
  return result;
}
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
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
483
484
485
486
487
}

/// Compute the arc tangent of \p x / \p y using the signs of both arguments
/// to determine the quadrant of the return value.
///
488
489
static inline VTKM_EXEC_CONT vtkm::Float32 ATan2(vtkm::Float32 x, vtkm::Float32 y)
{
490
#ifdef VTKM_CUDA
491
  return VTKM_CUDA_MATH_FUNCTION_32(atan2)(x, y);
492
#else
493
  return std::atan2(x, y);
494
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
495
}
496
497
static inline VTKM_EXEC_CONT vtkm::Float64 ATan2(vtkm::Float64 x, vtkm::Float64 y)
{
498
#ifdef VTKM_CUDA
499
  return VTKM_CUDA_MATH_FUNCTION_64(atan2)(x, y);
500
#else
501
  return std::atan2(x, y);
502
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
503
504
505
506
}

/// Compute the hyperbolic sine of \p x.
///
507
508
509
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type SinH(T x)
{
510
#ifdef VTKM_CUDA
511
  return VTKM_CUDA_MATH_FUNCTION_64(sinh)(static_cast<vtkm::Float64>(x));
512
#else
513
  return std::sinh(static_cast<vtkm::Float64>(x));
514
515
#endif
}
516
517
518
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float32>::Type SinH(vtkm::Float32 x)
{
519
520
521
522
523
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(sinh)(x);
#else
  return std::sinh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
524
}
525
526
527
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float64>::Type SinH(vtkm::Float64 x)
{
528
529
530
531
532
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(sinh)(x);
#else
  return std::sinh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
533
}
534
535
536
537
538
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
539
540
541
542
543
544
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::SinH(x[index]);
  }
  return result;
}
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
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
565
566
567
568
}

/// Compute the hyperbolic cosine of \p x.
///
569
570
571
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type CosH(T x)
{
572
#ifdef VTKM_CUDA
573
  return VTKM_CUDA_MATH_FUNCTION_64(cosh)(static_cast<vtkm::Float64>(x));
574
#else
575
  return std::cosh(static_cast<vtkm::Float64>(x));
576
577
#endif
}
578
579
580
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float32>::Type CosH(vtkm::Float32 x)
{
581
582
583
584
585
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(cosh)(x);
#else
  return std::cosh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
586
}
587
588
589
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float64>::Type CosH(vtkm::Float64 x)
{
590
591
592
593
594
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(cosh)(x);
#else
  return std::cosh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
595
}
596
597
598
599
600
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
601
602
603
604
605
606
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::CosH(x[index]);
  }
  return result;
}
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
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
627
628
629
630
}

/// Compute the hyperbolic tangent of \p x.
///
631
632
633
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type TanH(T x)
{
634
#ifdef VTKM_CUDA
635
  return VTKM_CUDA_MATH_FUNCTION_64(tanh)(static_cast<vtkm::Float64>(x));
636
#else
637
  return std::tanh(static_cast<vtkm::Float64>(x));
638
639
#endif
}
640
641
642
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float32>::Type TanH(vtkm::Float32 x)
{
643
644
645
646
647
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(tanh)(x);
#else
  return std::tanh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
648
}
649
650
651
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float64>::Type TanH(vtkm::Float64 x)
{
652
653
654
655
656
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(tanh)(x);
#else
  return std::tanh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
657
}
658
659
660
661
662
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
663
664
665
666
667
668
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::TanH(x[index]);
  }
  return result;
}
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
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
689
690
691
692
}

/// Compute the hyperbolic arc sine of \p x.
///
693
694
695
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type ASinH(T x)
{
696
#ifdef VTKM_CUDA
697
  return VTKM_CUDA_MATH_FUNCTION_64(asinh)(static_cast<vtkm::Float64>(x));
698
#else
699
  return std::asinh(static_cast<vtkm::Float64>(x));
700
701
#endif
}
702
703
704
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float32>::Type ASinH(vtkm::Float32 x)
{
705
706
707
708
709
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(asinh)(x);
#else
  return std::asinh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
710
}
711
712
713
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float64>::Type ASinH(vtkm::Float64 x)
{
714
715
716
717
718
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(asinh)(x);
#else
  return std::asinh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
719
}
720
721
722
723
724
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
725
726
727
728
729
730
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::ASinH(x[index]);
  }
  return result;
}
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
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
751
752
753
754
}

/// Compute the hyperbolic arc cosine of \p x.
///
755
756
757
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type ACosH(T x)
{
758
#ifdef VTKM_CUDA
759
  return VTKM_CUDA_MATH_FUNCTION_64(acosh)(static_cast<vtkm::Float64>(x));
760
#else
761
  return std::acosh(static_cast<vtkm::Float64>(x));
762
763
#endif
}
764
765
766
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float32>::Type ACosH(vtkm::Float32 x)
{
767
768
769
770
771
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(acosh)(x);
#else
  return std::acosh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
772
}
773
774
775
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float64>::Type ACosH(vtkm::Float64 x)
{
776
777
778
779
780
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(acosh)(x);
#else
  return std::acosh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
781
}
782
783
784
785
786
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
787
788
789
790
791
792
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::ACosH(x[index]);
  }
  return result;
}
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
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
813
814
815
816
}

/// Compute the hyperbolic arc tangent of \p x.
///
817
818
819
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type ATanH(T x)
{
820
#ifdef VTKM_CUDA
821
  return VTKM_CUDA_MATH_FUNCTION_64(atanh)(static_cast<vtkm::Float64>(x));
822
#else
823
  return std::atanh(static_cast<vtkm::Float64>(x));
824
825
#endif
}
826
827
828
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float32>::Type ATanH(vtkm::Float32 x)
{
829
830
831
832
833
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(atanh)(x);
#else
  return std::atanh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
834
}
835
836
837
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float64>::Type ATanH(vtkm::Float64 x)
{
838
839
840
841
842
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(atanh)(x);
#else
  return std::atanh(x);
#endif
Kenneth Moreland's avatar
Kenneth Moreland committed
843
}
844
845
846
847
848
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
849
850
851
852
853
854
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::ATanH(x[index]);
  }
  return result;
}
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
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
875
876
}

877
//-----------------------------------------------------------------------------
878
879
/// Computes \p x raised to the power of \p y.
///
880
881
static inline VTKM_EXEC_CONT vtkm::Float32 Pow(vtkm::Float32 x, vtkm::Float32 y)
{
882
#ifdef VTKM_CUDA
883
  return VTKM_CUDA_MATH_FUNCTION_32(pow)(x, y);
884
#else
885
  return std::pow(x, y);
886
#endif
887
}
888
889
static inline VTKM_EXEC_CONT vtkm::Float64 Pow(vtkm::Float64 x, vtkm::Float64 y)
{
890
#ifdef VTKM_CUDA
891
  return VTKM_CUDA_MATH_FUNCTION_64(pow)(x, y);
892
#else
893
  return std::pow(x, y);
894
#endif
895
896
}

897
898
/// Compute the square root of \p x.
///
899
900
901
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Sqrt(T x)
{
902
#ifdef VTKM_CUDA
903
  return VTKM_CUDA_MATH_FUNCTION_64(sqrt)(static_cast<vtkm::Float64>(x));
904
#else
905
  return std::sqrt(static_cast<vtkm::Float64>(x));
906
907
#endif
}
908
909
910
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float32>::Type Sqrt(vtkm::Float32 x)
{
911
912
913
914
915
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(sqrt)(x);
#else
  return std::sqrt(x);
#endif
916
}
917
918
919
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float64>::Type Sqrt(vtkm::Float64 x)
{
920
921
922
923
924
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(sqrt)(x);
#else
  return std::sqrt(x);
#endif
925
}
926
927
928
929
930
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;
931
932
933
934
935
936
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::Sqrt(x[index]);
  }
  return result;
}
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
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]));
957
958
}

959
960
961
962
963
964
/// 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
965
966
static inline VTKM_EXEC_CONT vtkm::Float32 RSqrt(vtkm::Float32 x)
{
967
  return rsqrtf(x);
968
}
969
970
static inline VTKM_EXEC_CONT vtkm::Float64 RSqrt(vtkm::Float64 x)
{
971
  return rsqrt(x);
972
}
973
974
975
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Float64 RSqrt(T x)
{
976
977
  return rsqrt(static_cast<vtkm::Float64>(x));
}
978
979
980
981
#else  // !VTKM_CUDA
static inline VTKM_EXEC_CONT vtkm::Float32 RSqrt(vtkm::Float32 x)
{
  return 1 / vtkm::Sqrt(x);
982
}
983
984
985
static inline VTKM_EXEC_CONT vtkm::Float64 RSqrt(vtkm::Float64 x)
{
  return 1 / vtkm::Sqrt(x);
986
}
987
988
989
990
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Float64 RSqrt(T x)
{
  return 1 / static_cast<vtkm::Float64>(x);
991
}
992
#endif // !VTKM_CUDA
993

994
995
996
997
998
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;
999
1000
1001
1002
1003
1004
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::RSqrt(x[index]);
  }
  return result;
}
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
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]));
1025
1026
1027
1028
}

/// Compute the cube root of \p x.
///
1029
1030
1031
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Cbrt(T x)
{
1032
#ifdef VTKM_CUDA
1033
  return VTKM_CUDA_MATH_FUNCTION_64(cbrt)(static_cast<vtkm::Float64>(x));
1034
#else
1035
  return std::cbrt(static_cast<vtkm::Float64>(x));
1036
1037
#endif
}
1038
1039
1040
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float32>::Type Cbrt(vtkm::Float32 x)
{
1041
1042
1043
1044
1045
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(cbrt)(x);
#else
  return std::cbrt(x);
#endif
1046
}
1047
1048
1049
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float64>::Type Cbrt(vtkm::Float64 x)
{
1050
1051
1052
1053
1054
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_64(cbrt)(x);
#else
  return std::cbrt(x);
#endif
1055
}
1056
1057
1058
1059
1060
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;
1061
1062
1063
1064
1065
1066
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::Cbrt(x[index]);
  }
  return result;
}
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
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]));
1087
1088
1089
1090
1091
1092
1093
1094
}

/// 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
1095
1096
static inline VTKM_EXEC_CONT vtkm::Float32 RCbrt(vtkm::Float32 x)
{
1097
  return rcbrtf(x);
1098
}
1099
1100
static inline VTKM_EXEC_CONT vtkm::Float64 RCbrt(vtkm::Float64 x)
{
1101
  return rcbrt(x);
1102
}
1103
1104
1105
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Float64 RCbrt(T x)
{
1106
1107
  return rcbrt(static_cast<vtkm::Float64>(x));
}
1108
1109
1110
1111
#else  // !VTKM_CUDA
static inline VTKM_EXEC_CONT vtkm::Float32 RCbrt(vtkm::Float32 x)
{
  return 1 / vtkm::Cbrt(x);
1112
}
1113
1114
1115
static inline VTKM_EXEC_CONT vtkm::Float64 RCbrt(vtkm::Float64 x)
{
  return 1 / vtkm::Cbrt(x);
1116
}
1117
1118
1119
1120
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Float64 RCbrt(T x)
{
  return 1 / vtkm::Cbrt(static_cast<vtkm::Float64>(x));
1121
}
1122
#endif // !VTKM_CUDA
1123

1124
1125
1126
1127
1128
template <typename T, vtkm::IdComponent N>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> RCbrt(
  const vtkm::Vec<T, N>& x)
{
  vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> result;
1129
1130
1131
1132
1133
1134
  for (vtkm::IdComponent index = 0; index < N; index++)
  {
    result[index] = vtkm::RCbrt(x[index]);
  }
  return result;
}
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4> RCbrt(
  const vtkm::Vec<T, 4>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 4>(
    vtkm::RCbrt(x[0]), vtkm::RCbrt(x[1]), vtkm::RCbrt(x[2]), vtkm::RCbrt(x[3]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3> RCbrt(
  const vtkm::Vec<T, 3>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 3>(
    vtkm::RCbrt(x[0]), vtkm::RCbrt(x[1]), vtkm::RCbrt(x[2]));
}
template <typename T>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2> RCbrt(
  const vtkm::Vec<T, 2>& x)
{
  return vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, 2>(vtkm::RCbrt(x[0]),
                                                                         vtkm::RCbrt(x[1]));
1155
1156
1157
1158
}

/// Computes e**\p x, the base-e exponential of \p x.
///
1159
1160
1161
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Exp(T x)
{
1162
#ifdef VTKM_CUDA
1163
  return VTKM_CUDA_MATH_FUNCTION_64(exp)(static_cast<vtkm::Float64>(x));
1164
#else
1165
  return std::exp(static_cast<vtkm::Float64>(x));
1166
1167
#endif
}
1168
1169
1170
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float32>::Type Exp(vtkm::Float32 x)
{
1171
1172
1173
1174
1175
#ifdef VTKM_CUDA
  return VTKM_CUDA_MATH_FUNCTION_32(exp)(x);
#else
  return std::exp(x);
#endif
1176
}
1177
1178
1179
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float64>::Type Exp(vtkm::Float64 x)
{