VTK-m  2.0
Math.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 // **** DO NOT EDIT THIS FILE!!! ****
11 // This file is automatically generated by Math.h.in
12 
13 #ifndef vtk_m_Math_h
14 #define vtk_m_Math_h
15 
16 #include <vtkm/TypeTraits.h>
17 #include <vtkm/Types.h>
18 #include <vtkm/VecTraits.h>
19 
20 #include <limits> // must be found with or without CUDA.
21 #ifndef VTKM_CUDA
22 #include <cmath>
23 #include <cstring>
24 #include <limits.h>
25 #include <math.h>
26 #include <stdlib.h>
27 #endif // !VTKM_CUDA
28 
29 #if !defined(VTKM_CUDA_DEVICE_PASS)
30 #define VTKM_USE_STL
31 #include <algorithm>
32 #endif
33 
34 #ifdef VTKM_MSVC
35 #include <intrin.h> // For bitwise intrinsics (__popcnt, etc)
36 #include <vtkm/internal/Windows.h> // for types used by MSVC intrinsics.
37 #ifndef VTKM_CUDA
38 #include <math.h>
39 #endif // VTKM_CUDA
40 #endif // VTKM_MSVC
41 
42 #define VTKM_CUDA_MATH_FUNCTION_32(func) func##f
43 #define VTKM_CUDA_MATH_FUNCTION_64(func) func
44 
45 // clang-format off
46 namespace vtkm
47 {
48 
49 //-----------------------------------------------------------------------------
50 namespace detail
51 {
52 template <typename T>
53 struct FloatingPointReturnType
54 {
55  using ctype = typename vtkm::VecTraits<T>::ComponentType;
56  using representable_as_float_type = std::integral_constant<bool,
57  ((sizeof(ctype) < sizeof(float)) || std::is_same<ctype, vtkm::Float32>::value)>;
58  using Type = typename std::conditional<representable_as_float_type::value,
60  vtkm::Float64>::type;
61 };
62 } // namespace detail
63 
66 static constexpr inline VTKM_EXEC_CONT vtkm::Float32 TwoPif()
67 {
68  return 6.28318530717958647692528676655900576f;
69 }
70 
73 static constexpr inline VTKM_EXEC_CONT vtkm::Float32 Pif()
74 {
75  return 3.14159265358979323846264338327950288f;
76 }
77 
80 static constexpr inline VTKM_EXEC_CONT vtkm::Float32 Pi_2f()
81 {
82  return 1.57079632679489661923132169163975144f;
83 }
84 
87 static constexpr inline VTKM_EXEC_CONT vtkm::Float32 Pi_3f()
88 {
89  return 1.04719755119659774615421446109316762f;
90 }
91 
94 static constexpr inline VTKM_EXEC_CONT vtkm::Float32 Pi_4f()
95 {
96  return 0.78539816339744830961566084581987572f;
97 }
98 
101 static constexpr inline VTKM_EXEC_CONT vtkm::Float32 Pi_180f()
102 {
103  return 0.01745329251994329547437168059786927f;
104 }
105 
108 static constexpr inline VTKM_EXEC_CONT vtkm::Float64 TwoPi()
109 {
110  return 6.28318530717958647692528676655900576;
111 }
112 
115 static constexpr inline VTKM_EXEC_CONT vtkm::Float64 Pi()
116 {
117  return 3.14159265358979323846264338327950288;
118 }
119 
122 static constexpr inline VTKM_EXEC_CONT vtkm::Float64 Pi_2()
123 {
124  return 1.57079632679489661923132169163975144;
125 }
126 
129 static constexpr inline VTKM_EXEC_CONT vtkm::Float64 Pi_3()
130 {
131  return 1.04719755119659774615421446109316762;
132 }
133 
136 static constexpr inline VTKM_EXEC_CONT vtkm::Float64 Pi_4()
137 {
138  return 0.78539816339744830961566084581987572;
139 }
140 
143 static constexpr inline VTKM_EXEC_CONT vtkm::Float64 Pi_180()
144 {
145  return 0.01745329251994329547437168059786927;
146 }
147 
150 template <typename T>
151  static constexpr inline VTKM_EXEC_CONT auto TwoPi() -> typename detail::FloatingPointReturnType<T>::Type
152  {
153  using FT = typename detail::FloatingPointReturnType<T>::Type;
154  using RAFT = typename detail::FloatingPointReturnType<T>::representable_as_float_type;
155  return static_cast<FT>(RAFT::value ? TwoPif() : TwoPi());
156  }
157 
160 template <typename T>
161  static constexpr inline VTKM_EXEC_CONT auto Pi() -> typename detail::FloatingPointReturnType<T>::Type
162  {
163  using FT = typename detail::FloatingPointReturnType<T>::Type;
164  using RAFT = typename detail::FloatingPointReturnType<T>::representable_as_float_type;
165  return static_cast<FT>(RAFT::value ? Pif() : Pi());
166  }
167 
170 template <typename T>
171  static constexpr inline VTKM_EXEC_CONT auto Pi_2() -> typename detail::FloatingPointReturnType<T>::Type
172  {
173  using FT = typename detail::FloatingPointReturnType<T>::Type;
174  using RAFT = typename detail::FloatingPointReturnType<T>::representable_as_float_type;
175  return static_cast<FT>(RAFT::value ? Pi_2f() : Pi_2());
176  }
177 
180 template <typename T>
181  static constexpr inline VTKM_EXEC_CONT auto Pi_3() -> typename detail::FloatingPointReturnType<T>::Type
182  {
183  using FT = typename detail::FloatingPointReturnType<T>::Type;
184  using RAFT = typename detail::FloatingPointReturnType<T>::representable_as_float_type;
185  return static_cast<FT>(RAFT::value ? Pi_3f() : Pi_3());
186  }
187 
190 template <typename T>
191  static constexpr inline VTKM_EXEC_CONT auto Pi_4() -> typename detail::FloatingPointReturnType<T>::Type
192  {
193  using FT = typename detail::FloatingPointReturnType<T>::Type;
194  using RAFT = typename detail::FloatingPointReturnType<T>::representable_as_float_type;
195  return static_cast<FT>(RAFT::value ? Pi_4f() : Pi_4());
196  }
199 template <typename T>
200  static constexpr inline VTKM_EXEC_CONT auto Pi_180() -> typename detail::FloatingPointReturnType<T>::Type
201  {
202  using FT = typename detail::FloatingPointReturnType<T>::Type;
203  using RAFT = typename detail::FloatingPointReturnType<T>::representable_as_float_type;
204  return static_cast<FT>(RAFT::value ? Pi_180f() : Pi_180());
205  }
206 
209 
211 {
212 #ifdef VTKM_CUDA
213  return VTKM_CUDA_MATH_FUNCTION_32(sin)(x);
214 #else
215  return std::sin(x);
216 #endif
217 }
218 
220 {
221 #ifdef VTKM_CUDA
222  return VTKM_CUDA_MATH_FUNCTION_64(sin)(x);
223 #else
224  return std::sin(x);
225 #endif
226 }
227 template <typename T>
228 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Sin(const T& x)
229 {
230  using RT = typename detail::FloatingPointReturnType<T>::Type;
231  return vtkm::Sin(static_cast<RT>(x));
232 }
233 template <typename T, vtkm::IdComponent N>
235  const vtkm::Vec<T, N>& x)
236 {
238  for (vtkm::IdComponent index = 0; index < N; index++)
239  {
240  result[index] = vtkm::Sin(x[index]);
241  }
242  return result;
243 }
244 template <typename T>
246  const vtkm::Vec<T, 4>& x)
247 {
249  vtkm::Sin(x[0]), vtkm::Sin(x[1]), vtkm::Sin(x[2]), vtkm::Sin(x[3]));
250 }
251 template <typename T>
253  const vtkm::Vec<T, 3>& x)
254 {
256  vtkm::Sin(x[0]), vtkm::Sin(x[1]), vtkm::Sin(x[2]));
257 }
258 template <typename T>
260  const vtkm::Vec<T, 2>& x)
261 {
263  vtkm::Sin(x[1]));
264 }
265 
268 
270 {
271 #ifdef VTKM_CUDA
272  return VTKM_CUDA_MATH_FUNCTION_32(cos)(x);
273 #else
274  return std::cos(x);
275 #endif
276 }
277 
279 {
280 #ifdef VTKM_CUDA
281  return VTKM_CUDA_MATH_FUNCTION_64(cos)(x);
282 #else
283  return std::cos(x);
284 #endif
285 }
286 template <typename T>
287 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Cos(const T& x)
288 {
289  using RT = typename detail::FloatingPointReturnType<T>::Type;
290  return vtkm::Cos(static_cast<RT>(x));
291 }
292 template <typename T, vtkm::IdComponent N>
294  const vtkm::Vec<T, N>& x)
295 {
297  for (vtkm::IdComponent index = 0; index < N; index++)
298  {
299  result[index] = vtkm::Cos(x[index]);
300  }
301  return result;
302 }
303 template <typename T>
305  const vtkm::Vec<T, 4>& x)
306 {
308  vtkm::Cos(x[0]), vtkm::Cos(x[1]), vtkm::Cos(x[2]), vtkm::Cos(x[3]));
309 }
310 template <typename T>
312  const vtkm::Vec<T, 3>& x)
313 {
315  vtkm::Cos(x[0]), vtkm::Cos(x[1]), vtkm::Cos(x[2]));
316 }
317 template <typename T>
319  const vtkm::Vec<T, 2>& x)
320 {
322  vtkm::Cos(x[1]));
323 }
324 
327 
329 {
330 #ifdef VTKM_CUDA
331  return VTKM_CUDA_MATH_FUNCTION_32(tan)(x);
332 #else
333  return std::tan(x);
334 #endif
335 }
336 
338 {
339 #ifdef VTKM_CUDA
340  return VTKM_CUDA_MATH_FUNCTION_64(tan)(x);
341 #else
342  return std::tan(x);
343 #endif
344 }
345 template <typename T>
346 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Tan(const T& x)
347 {
348  using RT = typename detail::FloatingPointReturnType<T>::Type;
349  return vtkm::Tan(static_cast<RT>(x));
350 }
351 template <typename T, vtkm::IdComponent N>
353  const vtkm::Vec<T, N>& x)
354 {
356  for (vtkm::IdComponent index = 0; index < N; index++)
357  {
358  result[index] = vtkm::Tan(x[index]);
359  }
360  return result;
361 }
362 template <typename T>
364  const vtkm::Vec<T, 4>& x)
365 {
367  vtkm::Tan(x[0]), vtkm::Tan(x[1]), vtkm::Tan(x[2]), vtkm::Tan(x[3]));
368 }
369 template <typename T>
371  const vtkm::Vec<T, 3>& x)
372 {
374  vtkm::Tan(x[0]), vtkm::Tan(x[1]), vtkm::Tan(x[2]));
375 }
376 template <typename T>
378  const vtkm::Vec<T, 2>& x)
379 {
381  vtkm::Tan(x[1]));
382 }
383 
386 
388 {
389 #ifdef VTKM_CUDA
390  return VTKM_CUDA_MATH_FUNCTION_32(asin)(x);
391 #else
392  return std::asin(x);
393 #endif
394 }
395 
397 {
398 #ifdef VTKM_CUDA
399  return VTKM_CUDA_MATH_FUNCTION_64(asin)(x);
400 #else
401  return std::asin(x);
402 #endif
403 }
404 template <typename T>
405 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type ASin(const T& x)
406 {
407  using RT = typename detail::FloatingPointReturnType<T>::Type;
408  return vtkm::ASin(static_cast<RT>(x));
409 }
410 template <typename T, vtkm::IdComponent N>
412  const vtkm::Vec<T, N>& x)
413 {
415  for (vtkm::IdComponent index = 0; index < N; index++)
416  {
417  result[index] = vtkm::ASin(x[index]);
418  }
419  return result;
420 }
421 template <typename T>
423  const vtkm::Vec<T, 4>& x)
424 {
426  vtkm::ASin(x[0]), vtkm::ASin(x[1]), vtkm::ASin(x[2]), vtkm::ASin(x[3]));
427 }
428 template <typename T>
430  const vtkm::Vec<T, 3>& x)
431 {
433  vtkm::ASin(x[0]), vtkm::ASin(x[1]), vtkm::ASin(x[2]));
434 }
435 template <typename T>
437  const vtkm::Vec<T, 2>& x)
438 {
440  vtkm::ASin(x[1]));
441 }
442 
445 
447 {
448 #ifdef VTKM_CUDA
449  return VTKM_CUDA_MATH_FUNCTION_32(acos)(x);
450 #else
451  return std::acos(x);
452 #endif
453 }
454 
456 {
457 #ifdef VTKM_CUDA
458  return VTKM_CUDA_MATH_FUNCTION_64(acos)(x);
459 #else
460  return std::acos(x);
461 #endif
462 }
463 template <typename T>
464 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type ACos(const T& x)
465 {
466  using RT = typename detail::FloatingPointReturnType<T>::Type;
467  return vtkm::ACos(static_cast<RT>(x));
468 }
469 template <typename T, vtkm::IdComponent N>
471  const vtkm::Vec<T, N>& x)
472 {
474  for (vtkm::IdComponent index = 0; index < N; index++)
475  {
476  result[index] = vtkm::ACos(x[index]);
477  }
478  return result;
479 }
480 template <typename T>
482  const vtkm::Vec<T, 4>& x)
483 {
485  vtkm::ACos(x[0]), vtkm::ACos(x[1]), vtkm::ACos(x[2]), vtkm::ACos(x[3]));
486 }
487 template <typename T>
489  const vtkm::Vec<T, 3>& x)
490 {
492  vtkm::ACos(x[0]), vtkm::ACos(x[1]), vtkm::ACos(x[2]));
493 }
494 template <typename T>
496  const vtkm::Vec<T, 2>& x)
497 {
499  vtkm::ACos(x[1]));
500 }
501 
504 
506 {
507 #ifdef VTKM_CUDA
508  return VTKM_CUDA_MATH_FUNCTION_32(atan)(x);
509 #else
510  return std::atan(x);
511 #endif
512 }
513 
515 {
516 #ifdef VTKM_CUDA
517  return VTKM_CUDA_MATH_FUNCTION_64(atan)(x);
518 #else
519  return std::atan(x);
520 #endif
521 }
522 template <typename T>
523 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type ATan(const T& x)
524 {
525  using RT = typename detail::FloatingPointReturnType<T>::Type;
526  return vtkm::ATan(static_cast<RT>(x));
527 }
528 template <typename T, vtkm::IdComponent N>
530  const vtkm::Vec<T, N>& x)
531 {
533  for (vtkm::IdComponent index = 0; index < N; index++)
534  {
535  result[index] = vtkm::ATan(x[index]);
536  }
537  return result;
538 }
539 template <typename T>
541  const vtkm::Vec<T, 4>& x)
542 {
544  vtkm::ATan(x[0]), vtkm::ATan(x[1]), vtkm::ATan(x[2]), vtkm::ATan(x[3]));
545 }
546 template <typename T>
548  const vtkm::Vec<T, 3>& x)
549 {
551  vtkm::ATan(x[0]), vtkm::ATan(x[1]), vtkm::ATan(x[2]));
552 }
553 template <typename T>
555  const vtkm::Vec<T, 2>& x)
556 {
558  vtkm::ATan(x[1]));
559 }
560 
565 {
566 #ifdef VTKM_CUDA
567  return VTKM_CUDA_MATH_FUNCTION_32(atan2)(x, y);
568 #else
569  return std::atan2(x, y);
570 #endif
571 }
573 {
574 #ifdef VTKM_CUDA
575  return VTKM_CUDA_MATH_FUNCTION_64(atan2)(x, y);
576 #else
577  return std::atan2(x, y);
578 #endif
579 }
580 
583 
585 {
586 #ifdef VTKM_CUDA
587  return VTKM_CUDA_MATH_FUNCTION_32(sinh)(x);
588 #else
589  return std::sinh(x);
590 #endif
591 }
592 
594 {
595 #ifdef VTKM_CUDA
596  return VTKM_CUDA_MATH_FUNCTION_64(sinh)(x);
597 #else
598  return std::sinh(x);
599 #endif
600 }
601 template <typename T>
602 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type SinH(const T& x)
603 {
604  using RT = typename detail::FloatingPointReturnType<T>::Type;
605  return vtkm::SinH(static_cast<RT>(x));
606 }
607 template <typename T, vtkm::IdComponent N>
609  const vtkm::Vec<T, N>& x)
610 {
612  for (vtkm::IdComponent index = 0; index < N; index++)
613  {
614  result[index] = vtkm::SinH(x[index]);
615  }
616  return result;
617 }
618 template <typename T>
620  const vtkm::Vec<T, 4>& x)
621 {
623  vtkm::SinH(x[0]), vtkm::SinH(x[1]), vtkm::SinH(x[2]), vtkm::SinH(x[3]));
624 }
625 template <typename T>
627  const vtkm::Vec<T, 3>& x)
628 {
630  vtkm::SinH(x[0]), vtkm::SinH(x[1]), vtkm::SinH(x[2]));
631 }
632 template <typename T>
634  const vtkm::Vec<T, 2>& x)
635 {
637  vtkm::SinH(x[1]));
638 }
639 
642 
644 {
645 #ifdef VTKM_CUDA
646  return VTKM_CUDA_MATH_FUNCTION_32(cosh)(x);
647 #else
648  return std::cosh(x);
649 #endif
650 }
651 
653 {
654 #ifdef VTKM_CUDA
655  return VTKM_CUDA_MATH_FUNCTION_64(cosh)(x);
656 #else
657  return std::cosh(x);
658 #endif
659 }
660 template <typename T>
661 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type CosH(const T& x)
662 {
663  using RT = typename detail::FloatingPointReturnType<T>::Type;
664  return vtkm::CosH(static_cast<RT>(x));
665 }
666 template <typename T, vtkm::IdComponent N>
668  const vtkm::Vec<T, N>& x)
669 {
671  for (vtkm::IdComponent index = 0; index < N; index++)
672  {
673  result[index] = vtkm::CosH(x[index]);
674  }
675  return result;
676 }
677 template <typename T>
679  const vtkm::Vec<T, 4>& x)
680 {
682  vtkm::CosH(x[0]), vtkm::CosH(x[1]), vtkm::CosH(x[2]), vtkm::CosH(x[3]));
683 }
684 template <typename T>
686  const vtkm::Vec<T, 3>& x)
687 {
689  vtkm::CosH(x[0]), vtkm::CosH(x[1]), vtkm::CosH(x[2]));
690 }
691 template <typename T>
693  const vtkm::Vec<T, 2>& x)
694 {
696  vtkm::CosH(x[1]));
697 }
698 
701 
703 {
704 #ifdef VTKM_CUDA
705  return VTKM_CUDA_MATH_FUNCTION_32(tanh)(x);
706 #else
707  return std::tanh(x);
708 #endif
709 }
710 
712 {
713 #ifdef VTKM_CUDA
714  return VTKM_CUDA_MATH_FUNCTION_64(tanh)(x);
715 #else
716  return std::tanh(x);
717 #endif
718 }
719 template <typename T>
720 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type TanH(const T& x)
721 {
722  using RT = typename detail::FloatingPointReturnType<T>::Type;
723  return vtkm::TanH(static_cast<RT>(x));
724 }
725 template <typename T, vtkm::IdComponent N>
727  const vtkm::Vec<T, N>& x)
728 {
730  for (vtkm::IdComponent index = 0; index < N; index++)
731  {
732  result[index] = vtkm::TanH(x[index]);
733  }
734  return result;
735 }
736 template <typename T>
738  const vtkm::Vec<T, 4>& x)
739 {
741  vtkm::TanH(x[0]), vtkm::TanH(x[1]), vtkm::TanH(x[2]), vtkm::TanH(x[3]));
742 }
743 template <typename T>
745  const vtkm::Vec<T, 3>& x)
746 {
748  vtkm::TanH(x[0]), vtkm::TanH(x[1]), vtkm::TanH(x[2]));
749 }
750 template <typename T>
752  const vtkm::Vec<T, 2>& x)
753 {
755  vtkm::TanH(x[1]));
756 }
757 
760 
762 {
763 #ifdef VTKM_CUDA
764  return VTKM_CUDA_MATH_FUNCTION_32(asinh)(x);
765 #else
766  return std::asinh(x);
767 #endif
768 }
769 
771 {
772 #ifdef VTKM_CUDA
773  return VTKM_CUDA_MATH_FUNCTION_64(asinh)(x);
774 #else
775  return std::asinh(x);
776 #endif
777 }
778 template <typename T>
779 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type ASinH(const T& x)
780 {
781  using RT = typename detail::FloatingPointReturnType<T>::Type;
782  return vtkm::ASinH(static_cast<RT>(x));
783 }
784 template <typename T, vtkm::IdComponent N>
786  const vtkm::Vec<T, N>& x)
787 {
789  for (vtkm::IdComponent index = 0; index < N; index++)
790  {
791  result[index] = vtkm::ASinH(x[index]);
792  }
793  return result;
794 }
795 template <typename T>
797  const vtkm::Vec<T, 4>& x)
798 {
800  vtkm::ASinH(x[0]), vtkm::ASinH(x[1]), vtkm::ASinH(x[2]), vtkm::ASinH(x[3]));
801 }
802 template <typename T>
804  const vtkm::Vec<T, 3>& x)
805 {
807  vtkm::ASinH(x[0]), vtkm::ASinH(x[1]), vtkm::ASinH(x[2]));
808 }
809 template <typename T>
811  const vtkm::Vec<T, 2>& x)
812 {
814  vtkm::ASinH(x[1]));
815 }
816 
819 
821 {
822 #ifdef VTKM_CUDA
823  return VTKM_CUDA_MATH_FUNCTION_32(acosh)(x);
824 #else
825  return std::acosh(x);
826 #endif
827 }
828 
830 {
831 #ifdef VTKM_CUDA
832  return VTKM_CUDA_MATH_FUNCTION_64(acosh)(x);
833 #else
834  return std::acosh(x);
835 #endif
836 }
837 template <typename T>
838 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type ACosH(const T& x)
839 {
840  using RT = typename detail::FloatingPointReturnType<T>::Type;
841  return vtkm::ACosH(static_cast<RT>(x));
842 }
843 template <typename T, vtkm::IdComponent N>
845  const vtkm::Vec<T, N>& x)
846 {
848  for (vtkm::IdComponent index = 0; index < N; index++)
849  {
850  result[index] = vtkm::ACosH(x[index]);
851  }
852  return result;
853 }
854 template <typename T>
856  const vtkm::Vec<T, 4>& x)
857 {
859  vtkm::ACosH(x[0]), vtkm::ACosH(x[1]), vtkm::ACosH(x[2]), vtkm::ACosH(x[3]));
860 }
861 template <typename T>
863  const vtkm::Vec<T, 3>& x)
864 {
866  vtkm::ACosH(x[0]), vtkm::ACosH(x[1]), vtkm::ACosH(x[2]));
867 }
868 template <typename T>
870  const vtkm::Vec<T, 2>& x)
871 {
873  vtkm::ACosH(x[1]));
874 }
875 
878 
880 {
881 #ifdef VTKM_CUDA
882  return VTKM_CUDA_MATH_FUNCTION_32(atanh)(x);
883 #else
884  return std::atanh(x);
885 #endif
886 }
887 
889 {
890 #ifdef VTKM_CUDA
891  return VTKM_CUDA_MATH_FUNCTION_64(atanh)(x);
892 #else
893  return std::atanh(x);
894 #endif
895 }
896 template <typename T>
897 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type ATanH(const T& x)
898 {
899  using RT = typename detail::FloatingPointReturnType<T>::Type;
900  return vtkm::ATanH(static_cast<RT>(x));
901 }
902 template <typename T, vtkm::IdComponent N>
904  const vtkm::Vec<T, N>& x)
905 {
907  for (vtkm::IdComponent index = 0; index < N; index++)
908  {
909  result[index] = vtkm::ATanH(x[index]);
910  }
911  return result;
912 }
913 template <typename T>
915  const vtkm::Vec<T, 4>& x)
916 {
918  vtkm::ATanH(x[0]), vtkm::ATanH(x[1]), vtkm::ATanH(x[2]), vtkm::ATanH(x[3]));
919 }
920 template <typename T>
922  const vtkm::Vec<T, 3>& x)
923 {
925  vtkm::ATanH(x[0]), vtkm::ATanH(x[1]), vtkm::ATanH(x[2]));
926 }
927 template <typename T>
929  const vtkm::Vec<T, 2>& x)
930 {
932  vtkm::ATanH(x[1]));
933 }
934 
935 //-----------------------------------------------------------------------------
939 {
940 #ifdef VTKM_CUDA
941  return VTKM_CUDA_MATH_FUNCTION_32(pow)(x, y);
942 #else
943  return std::pow(x, y);
944 #endif
945 }
947 {
948 #ifdef VTKM_CUDA
949  return VTKM_CUDA_MATH_FUNCTION_64(pow)(x, y);
950 #else
951  return std::pow(x, y);
952 #endif
953 }
954 
957 
959 {
960 #ifdef VTKM_CUDA
961  return VTKM_CUDA_MATH_FUNCTION_32(sqrt)(x);
962 #else
963  return std::sqrt(x);
964 #endif
965 }
966 
968 {
969 #ifdef VTKM_CUDA
970  return VTKM_CUDA_MATH_FUNCTION_64(sqrt)(x);
971 #else
972  return std::sqrt(x);
973 #endif
974 }
975 template <typename T>
976 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Sqrt(const T& x)
977 {
978  using RT = typename detail::FloatingPointReturnType<T>::Type;
979  return vtkm::Sqrt(static_cast<RT>(x));
980 }
981 template <typename T, vtkm::IdComponent N>
983  const vtkm::Vec<T, N>& x)
984 {
986  for (vtkm::IdComponent index = 0; index < N; index++)
987  {
988  result[index] = vtkm::Sqrt(x[index]);
989  }
990  return result;
991 }
992 template <typename T>
994  const vtkm::Vec<T, 4>& x)
995 {
997  vtkm::Sqrt(x[0]), vtkm::Sqrt(x[1]), vtkm::Sqrt(x[2]), vtkm::Sqrt(x[3]));
998 }
999 template <typename T>
1001  const vtkm::Vec<T, 3>& x)
1002 {
1004  vtkm::Sqrt(x[0]), vtkm::Sqrt(x[1]), vtkm::Sqrt(x[2]));
1005 }
1006 template <typename T>
1008  const vtkm::Vec<T, 2>& x)
1009 {
1011  vtkm::Sqrt(x[1]));
1012 }
1013 
1019 #ifdef VTKM_CUDA
1020 static inline VTKM_EXEC_CONT vtkm::Float32 RSqrt(vtkm::Float32 x)
1021 {
1022  return rsqrtf(x);
1023 }
1024 static inline VTKM_EXEC_CONT vtkm::Float64 RSqrt(vtkm::Float64 x)
1025 {
1026  return rsqrt(x);
1027 }
1028 template <typename T>
1029 static inline VTKM_EXEC_CONT vtkm::Float64 RSqrt(T x)
1030 {
1031  return rsqrt(static_cast<vtkm::Float64>(x));
1032 }
1033 #else // !VTKM_CUDA
1034 static inline VTKM_EXEC_CONT vtkm::Float32 RSqrt(vtkm::Float32 x)
1035 {
1036  return 1 / vtkm::Sqrt(x);
1037 }
1038 static inline VTKM_EXEC_CONT vtkm::Float64 RSqrt(vtkm::Float64 x)
1039 {
1040  return 1 / vtkm::Sqrt(x);
1041 }
1042 template <typename T>
1043 static inline VTKM_EXEC_CONT vtkm::Float64 RSqrt(T x)
1044 {
1045  return 1 / static_cast<vtkm::Float64>(x);
1046 }
1047 #endif // !VTKM_CUDA
1048 
1049 template <typename T, vtkm::IdComponent N>
1051  const vtkm::Vec<T, N>& x)
1052 {
1054  for (vtkm::IdComponent index = 0; index < N; index++)
1055  {
1056  result[index] = vtkm::RSqrt(x[index]);
1057  }
1058  return result;
1059 }
1060 template <typename T>
1062  const vtkm::Vec<T, 4>& x)
1063 {
1065  vtkm::RSqrt(x[0]), vtkm::RSqrt(x[1]), vtkm::RSqrt(x[2]), vtkm::RSqrt(x[3]));
1066 }
1067 template <typename T>
1069  const vtkm::Vec<T, 3>& x)
1070 {
1072  vtkm::RSqrt(x[0]), vtkm::RSqrt(x[1]), vtkm::RSqrt(x[2]));
1073 }
1074 template <typename T>
1076  const vtkm::Vec<T, 2>& x)
1077 {
1079  vtkm::RSqrt(x[1]));
1080 }
1081 
1084 
1086 {
1087 #ifdef VTKM_CUDA
1088  return VTKM_CUDA_MATH_FUNCTION_32(cbrt)(x);
1089 #else
1090  return std::cbrt(x);
1091 #endif
1092 }
1093 
1095 {
1096 #ifdef VTKM_CUDA
1097  return VTKM_CUDA_MATH_FUNCTION_64(cbrt)(x);
1098 #else
1099  return std::cbrt(x);
1100 #endif
1101 }
1102 template <typename T>
1103 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Cbrt(const T& x)
1104 {
1105  using RT = typename detail::FloatingPointReturnType<T>::Type;
1106  return vtkm::Cbrt(static_cast<RT>(x));
1107 }
1108 template <typename T, vtkm::IdComponent N>
1110  const vtkm::Vec<T, N>& x)
1111 {
1113  for (vtkm::IdComponent index = 0; index < N; index++)
1114  {
1115  result[index] = vtkm::Cbrt(x[index]);
1116  }
1117  return result;
1118 }
1119 template <typename T>
1121  const vtkm::Vec<T, 4>& x)
1122 {
1124  vtkm::Cbrt(x[0]), vtkm::Cbrt(x[1]), vtkm::Cbrt(x[2]), vtkm::Cbrt(x[3]));
1125 }
1126 template <typename T>
1128  const vtkm::Vec<T, 3>& x)
1129 {
1131  vtkm::Cbrt(x[0]), vtkm::Cbrt(x[1]), vtkm::Cbrt(x[2]));
1132 }
1133 template <typename T>
1135  const vtkm::Vec<T, 2>& x)
1136 {
1138  vtkm::Cbrt(x[1]));
1139 }
1140 
1146 #ifdef VTKM_CUDA
1147 static inline VTKM_EXEC_CONT vtkm::Float32 RCbrt(vtkm::Float32 x)
1148 {
1149  return rcbrtf(x);
1150 }
1151 static inline VTKM_EXEC_CONT vtkm::Float64 RCbrt(vtkm::Float64 x)
1152 {
1153  return rcbrt(x);
1154 }
1155 template <typename T>
1156 static inline VTKM_EXEC_CONT vtkm::Float64 RCbrt(T x)
1157 {
1158  return rcbrt(static_cast<vtkm::Float64>(x));
1159 }
1160 #else // !VTKM_CUDA
1161 static inline VTKM_EXEC_CONT vtkm::Float32 RCbrt(vtkm::Float32 x)
1162 {
1163  return 1 / vtkm::Cbrt(x);
1164 }
1165 static inline VTKM_EXEC_CONT vtkm::Float64 RCbrt(vtkm::Float64 x)
1166 {
1167  return 1 / vtkm::Cbrt(x);
1168 }
1169 template <typename T>
1170 static inline VTKM_EXEC_CONT vtkm::Float64 RCbrt(T x)
1171 {
1172  return 1 / vtkm::Cbrt(static_cast<vtkm::Float64>(x));
1173 }
1174 #endif // !VTKM_CUDA
1175 
1176 template <typename T, vtkm::IdComponent N>
1178  const vtkm::Vec<T, N>& x)
1179 {
1181  for (vtkm::IdComponent index = 0; index < N; index++)
1182  {
1183  result[index] = vtkm::RCbrt(x[index]);
1184  }
1185  return result;
1186 }
1187 template <typename T>
1189  const vtkm::Vec<T, 4>& x)
1190 {
1192  vtkm::RCbrt(x[0]), vtkm::RCbrt(x[1]), vtkm::RCbrt(x[2]), vtkm::RCbrt(x[3]));
1193 }
1194 template <typename T>
1196  const vtkm::Vec<T, 3>& x)
1197 {
1199  vtkm::RCbrt(x[0]), vtkm::RCbrt(x[1]), vtkm::RCbrt(x[2]));
1200 }
1201 template <typename T>
1203  const vtkm::Vec<T, 2>& x)
1204 {
1206  vtkm::RCbrt(x[1]));
1207 }
1208 
1211 
1213 {
1214 #ifdef VTKM_CUDA
1215  return VTKM_CUDA_MATH_FUNCTION_32(exp)(x);
1216 #else
1217  return std::exp(x);
1218 #endif
1219 }
1220 
1222 {
1223 #ifdef VTKM_CUDA
1224  return VTKM_CUDA_MATH_FUNCTION_64(exp)(x);
1225 #else
1226  return std::exp(x);
1227 #endif
1228 }
1229 template <typename T>
1230 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Exp(const T& x)
1231 {
1232  using RT = typename detail::FloatingPointReturnType<T>::Type;
1233  return vtkm::Exp(static_cast<RT>(x));
1234 }
1235 template <typename T, vtkm::IdComponent N>
1237  const vtkm::Vec<T, N>& x)
1238 {
1240  for (vtkm::IdComponent index = 0; index < N; index++)
1241  {
1242  result[index] = vtkm::Exp(x[index]);
1243  }
1244  return result;
1245 }
1246 template <typename T>
1248  const vtkm::Vec<T, 4>& x)
1249 {
1251  vtkm::Exp(x[0]), vtkm::Exp(x[1]), vtkm::Exp(x[2]), vtkm::Exp(x[3]));
1252 }
1253 template <typename T>
1255  const vtkm::Vec<T, 3>& x)
1256 {
1258  vtkm::Exp(x[0]), vtkm::Exp(x[1]), vtkm::Exp(x[2]));
1259 }
1260 template <typename T>
1262  const vtkm::Vec<T, 2>& x)
1263 {
1265  vtkm::Exp(x[1]));
1266 }
1267 
1270 
1272 {
1273 #ifdef VTKM_CUDA
1274  return VTKM_CUDA_MATH_FUNCTION_32(exp2)(x);
1275 #else
1276  return std::exp2(x);
1277 #endif
1278 }
1279 
1281 {
1282 #ifdef VTKM_CUDA
1283  return VTKM_CUDA_MATH_FUNCTION_64(exp2)(x);
1284 #else
1285  return std::exp2(x);
1286 #endif
1287 }
1288 template <typename T>
1289 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Exp2(const T& x)
1290 {
1291  using RT = typename detail::FloatingPointReturnType<T>::Type;
1292  return vtkm::Exp2(static_cast<RT>(x));
1293 }
1294 template <typename T, vtkm::IdComponent N>
1296  const vtkm::Vec<T, N>& x)
1297 {
1299  for (vtkm::IdComponent index = 0; index < N; index++)
1300  {
1301  result[index] = vtkm::Exp2(x[index]);
1302  }
1303  return result;
1304 }
1305 template <typename T>
1307  const vtkm::Vec<T, 4>& x)
1308 {
1310  vtkm::Exp2(x[0]), vtkm::Exp2(x[1]), vtkm::Exp2(x[2]), vtkm::Exp2(x[3]));
1311 }
1312 template <typename T>
1314  const vtkm::Vec<T, 3>& x)
1315 {
1317  vtkm::Exp2(x[0]), vtkm::Exp2(x[1]), vtkm::Exp2(x[2]));
1318 }
1319 template <typename T>
1321  const vtkm::Vec<T, 2>& x)
1322 {
1324  vtkm::Exp2(x[1]));
1325 }
1326 
1330 
1332 {
1333 #ifdef VTKM_CUDA
1334  return VTKM_CUDA_MATH_FUNCTION_32(expm1)(x);
1335 #else
1336  return std::expm1(x);
1337 #endif
1338 }
1339 
1341 {
1342 #ifdef VTKM_CUDA
1343  return VTKM_CUDA_MATH_FUNCTION_64(expm1)(x);
1344 #else
1345  return std::expm1(x);
1346 #endif
1347 }
1348 template <typename T>
1349 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type ExpM1(const T& x)
1350 {
1351  using RT = typename detail::FloatingPointReturnType<T>::Type;
1352  return vtkm::ExpM1(static_cast<RT>(x));
1353 }
1354 template <typename T, vtkm::IdComponent N>
1356  const vtkm::Vec<T, N>& x)
1357 {
1359  for (vtkm::IdComponent index = 0; index < N; index++)
1360  {
1361  result[index] = vtkm::ExpM1(x[index]);
1362  }
1363  return result;
1364 }
1365 template <typename T>
1367  const vtkm::Vec<T, 4>& x)
1368 {
1370  vtkm::ExpM1(x[0]), vtkm::ExpM1(x[1]), vtkm::ExpM1(x[2]), vtkm::ExpM1(x[3]));
1371 }
1372 template <typename T>
1374  const vtkm::Vec<T, 3>& x)
1375 {
1377  vtkm::ExpM1(x[0]), vtkm::ExpM1(x[1]), vtkm::ExpM1(x[2]));
1378 }
1379 template <typename T>
1381  const vtkm::Vec<T, 2>& x)
1382 {
1384  vtkm::ExpM1(x[1]));
1385 }
1386 
1389 #ifdef VTKM_CUDA
1390 static inline VTKM_EXEC_CONT vtkm::Float32 Exp10(vtkm::Float32 x)
1391 {
1392  return exp10f(x);
1393 }
1394 static inline VTKM_EXEC_CONT vtkm::Float64 Exp10(vtkm::Float64 x)
1395 {
1396  return exp10(x);
1397 }
1398 template <typename T>
1399 static inline VTKM_EXEC_CONT vtkm::Float64 Exp10(T x)
1400 {
1401  return exp10(static_cast<vtkm::Float64>(x));
1402 }
1403 #else // !VTKM_CUDA
1404 static inline VTKM_EXEC_CONT vtkm::Float32 Exp10(vtkm::Float32 x)
1405 {
1406  return vtkm::Pow(10, x);
1407 }
1408 static inline VTKM_EXEC_CONT vtkm::Float64 Exp10(vtkm::Float64 x)
1409 {
1410  return vtkm::Pow(10, x);
1411 }
1412 template <typename T>
1413 static inline VTKM_EXEC_CONT vtkm::Float64 Exp10(T x)
1414 {
1415  return vtkm::Pow(10, static_cast<vtkm::Float64>(x));
1416 }
1417 #endif // !VTKM_CUDA
1418 
1419 template <typename T, vtkm::IdComponent N>
1421  const vtkm::Vec<T, N>& x)
1422 {
1424  for (vtkm::IdComponent index = 0; index < N; index++)
1425  {
1426  result[index] = vtkm::Exp10(x[index]);
1427  }
1428  return result;
1429 }
1430 template <typename T>
1432  const vtkm::Vec<T, 4>& x)
1433 {
1435  vtkm::Exp10(x[0]), vtkm::Exp10(x[1]), vtkm::Exp10(x[2]), vtkm::Exp10(x[3]));
1436 }
1437 template <typename T>
1439  const vtkm::Vec<T, 3>& x)
1440 {
1442  vtkm::Exp10(x[0]), vtkm::Exp10(x[1]), vtkm::Exp10(x[2]));
1443 }
1444 template <typename T>
1446  const vtkm::Vec<T, 2>& x)
1447 {
1449  vtkm::Exp10(x[1]));
1450 }
1451 
1454 
1456 {
1457 #ifdef VTKM_CUDA
1458  return VTKM_CUDA_MATH_FUNCTION_32(log)(x);
1459 #else
1460  return std::log(x);
1461 #endif
1462 }
1463 
1465 {
1466 #ifdef VTKM_CUDA
1467  return VTKM_CUDA_MATH_FUNCTION_64(log)(x);
1468 #else
1469  return std::log(x);
1470 #endif
1471 }
1472 template <typename T>
1473 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Log(const T& x)
1474 {
1475  using RT = typename detail::FloatingPointReturnType<T>::Type;
1476  return vtkm::Log(static_cast<RT>(x));
1477 }
1478 template <typename T, vtkm::IdComponent N>
1480  const vtkm::Vec<T, N>& x)
1481 {
1483  for (vtkm::IdComponent index = 0; index < N; index++)
1484  {
1485  result[index] = vtkm::Log(x[index]);
1486  }
1487  return result;
1488 }
1489 template <typename T>
1491  const vtkm::Vec<T, 4>& x)
1492 {
1494  vtkm::Log(x[0]), vtkm::Log(x[1]), vtkm::Log(x[2]), vtkm::Log(x[3]));
1495 }
1496 template <typename T>
1498  const vtkm::Vec<T, 3>& x)
1499 {
1501  vtkm::Log(x[0]), vtkm::Log(x[1]), vtkm::Log(x[2]));
1502 }
1503 template <typename T>
1505  const vtkm::Vec<T, 2>& x)
1506 {
1508  vtkm::Log(x[1]));
1509 }
1510 
1513 
1515 {
1516 #ifdef VTKM_CUDA
1517  return VTKM_CUDA_MATH_FUNCTION_32(log2)(x);
1518 #else
1519  return std::log2(x);
1520 #endif
1521 }
1522 
1524 {
1525 #ifdef VTKM_CUDA
1526  return VTKM_CUDA_MATH_FUNCTION_64(log2)(x);
1527 #else
1528  return std::log2(x);
1529 #endif
1530 }
1531 template <typename T>
1532 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Log2(const T& x)
1533 {
1534  using RT = typename detail::FloatingPointReturnType<T>::Type;
1535  return vtkm::Log2(static_cast<RT>(x));
1536 }
1537 template <typename T, vtkm::IdComponent N>
1539  const vtkm::Vec<T, N>& x)
1540 {
1542  for (vtkm::IdComponent index = 0; index < N; index++)
1543  {
1544  result[index] = vtkm::Log2(x[index]);
1545  }
1546  return result;
1547 }
1548 template <typename T>
1550  const vtkm::Vec<T, 4>& x)
1551 {
1553  vtkm::Log2(x[0]), vtkm::Log2(x[1]), vtkm::Log2(x[2]), vtkm::Log2(x[3]));
1554 }
1555 template <typename T>
1557  const vtkm::Vec<T, 3>& x)
1558 {
1560  vtkm::Log2(x[0]), vtkm::Log2(x[1]), vtkm::Log2(x[2]));
1561 }
1562 template <typename T>
1564  const vtkm::Vec<T, 2>& x)
1565 {
1567  vtkm::Log2(x[1]));
1568 }
1569 
1572 
1574 {
1575 #ifdef VTKM_CUDA
1576  return VTKM_CUDA_MATH_FUNCTION_32(log10)(x);
1577 #else
1578  return std::log10(x);
1579 #endif
1580 }
1581 
1583 {
1584 #ifdef VTKM_CUDA
1585  return VTKM_CUDA_MATH_FUNCTION_64(log10)(x);
1586 #else
1587  return std::log10(x);
1588 #endif
1589 }
1590 template <typename T>
1591 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Log10(const T& x)
1592 {
1593  using RT = typename detail::FloatingPointReturnType<T>::Type;
1594  return vtkm::Log10(static_cast<RT>(x));
1595 }
1596 template <typename T, vtkm::IdComponent N>
1598  const vtkm::Vec<T, N>& x)
1599 {
1601  for (vtkm::IdComponent index = 0; index < N; index++)
1602  {
1603  result[index] = vtkm::Log10(x[index]);
1604  }
1605  return result;
1606 }
1607 template <typename T>
1609  const vtkm::Vec<T, 4>& x)
1610 {
1612  vtkm::Log10(x[0]), vtkm::Log10(x[1]), vtkm::Log10(x[2]), vtkm::Log10(x[3]));
1613 }
1614 template <typename T>
1616  const vtkm::Vec<T, 3>& x)
1617 {
1619  vtkm::Log10(x[0]), vtkm::Log10(x[1]), vtkm::Log10(x[2]));
1620 }
1621 template <typename T>
1623  const vtkm::Vec<T, 2>& x)
1624 {
1626  vtkm::Log10(x[1]));
1627 }
1628 
1631 
1633 {
1634 #ifdef VTKM_CUDA
1635  return VTKM_CUDA_MATH_FUNCTION_32(log1p)(x);
1636 #else
1637  return std::log1p(x);
1638 #endif
1639 }
1640 
1642 {
1643 #ifdef VTKM_CUDA
1644  return VTKM_CUDA_MATH_FUNCTION_64(log1p)(x);
1645 #else
1646  return std::log1p(x);
1647 #endif
1648 }
1649 template <typename T>
1650 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Log1P(const T& x)
1651 {
1652  using RT = typename detail::FloatingPointReturnType<T>::Type;
1653  return vtkm::Log1P(static_cast<RT>(x));
1654 }
1655 template <typename T, vtkm::IdComponent N>
1657  const vtkm::Vec<T, N>& x)
1658 {
1660  for (vtkm::IdComponent index = 0; index < N; index++)
1661  {
1662  result[index] = vtkm::Log1P(x[index]);
1663  }
1664  return result;
1665 }
1666 template <typename T>
1668  const vtkm::Vec<T, 4>& x)
1669 {
1671  vtkm::Log1P(x[0]), vtkm::Log1P(x[1]), vtkm::Log1P(x[2]), vtkm::Log1P(x[3]));
1672 }
1673 template <typename T>
1675  const vtkm::Vec<T, 3>& x)
1676 {
1678  vtkm::Log1P(x[0]), vtkm::Log1P(x[1]), vtkm::Log1P(x[2]));
1679 }
1680 template <typename T>
1682  const vtkm::Vec<T, 2>& x)
1683 {
1685  vtkm::Log1P(x[1]));
1686 }
1687 
1688 //-----------------------------------------------------------------------------
1691 template <typename T>
1692 static inline VTKM_EXEC_CONT T Max(const T& x, const T& y);
1693 #ifdef VTKM_USE_STL
1695 {
1696  return (std::max)(x, y);
1697 }
1699 {
1700  return (std::max)(x, y);
1701 }
1702 #else // !VTKM_USE_STL
1704 {
1705 #ifdef VTKM_CUDA
1706  return VTKM_CUDA_MATH_FUNCTION_32(fmax)(x, y);
1707 #else
1708  return std::fmax(x, y);
1709 #endif
1710 }
1712 {
1713 #ifdef VTKM_CUDA
1714  return VTKM_CUDA_MATH_FUNCTION_64(fmax)(x, y);
1715 #else
1716  return std::fmax(x, y);
1717 #endif
1718 }
1719 #endif // !VTKM_USE_STL
1720 
1723 template <typename T>
1724 static inline VTKM_EXEC_CONT T Min(const T& x, const T& y);
1725 #if defined(VTKM_USE_STL) && !defined(VTKM_HIP)
1727 {
1728  return (std::min)(x, y);
1729 }
1731 {
1732  return (std::min)(x, y);
1733 }
1734 #else // !VTKM_USE_STL OR HIP
1736 {
1737 #ifdef VTKM_CUDA
1738  return VTKM_CUDA_MATH_FUNCTION_32(fmin)(x, y);
1739 #else
1740  return std::fmin(x, y);
1741 #endif
1742 }
1744 {
1745 #ifdef VTKM_CUDA
1746  return VTKM_CUDA_MATH_FUNCTION_64(fmin)(x, y);
1747 #else
1748  return std::fmin(x, y);
1749 #endif
1750 }
1751 #endif // !VTKM_USE_STL
1752 
1753 namespace detail
1754 {
1755 
1756 template <typename T>
1757 static inline VTKM_EXEC_CONT T Max(T x, T y, vtkm::TypeTraitsScalarTag)
1758 {
1759  return (x < y) ? y : x;
1760 }
1761 
1762 template <typename T>
1763 static inline VTKM_EXEC_CONT T Max(const T& x, const T& y, vtkm::TypeTraitsVectorTag)
1764 {
1765  using Traits = vtkm::VecTraits<T>;
1766  T result;
1767  for (vtkm::IdComponent index = 0; index < Traits::NUM_COMPONENTS; index++)
1768  {
1769  Traits::SetComponent(
1770  result, index, vtkm::Max(Traits::GetComponent(x, index), Traits::GetComponent(y, index)));
1771  }
1772  return result;
1773 }
1774 
1775 template <typename T>
1776 static inline VTKM_EXEC_CONT T Min(T x, T y, vtkm::TypeTraitsScalarTag)
1777 {
1778  return (x < y) ? x : y;
1779 }
1780 
1781 template <typename T>
1782 static inline VTKM_EXEC_CONT T Min(const T& x, const T& y, vtkm::TypeTraitsVectorTag)
1783 {
1784  using Traits = vtkm::VecTraits<T>;
1785  T result;
1786  for (vtkm::IdComponent index = 0; index < Traits::NUM_COMPONENTS; index++)
1787  {
1788  Traits::SetComponent(
1789  result, index, vtkm::Min(Traits::GetComponent(x, index), Traits::GetComponent(y, index)));
1790  }
1791  return result;
1792 }
1793 
1794 } // namespace detail
1795 
1798 template <typename T>
1799 static inline VTKM_EXEC_CONT T Max(const T& x, const T& y)
1800 {
1801  return detail::Max(x, y, typename vtkm::TypeTraits<T>::DimensionalityTag());
1802 }
1803 
1806 template <typename T>
1807 static inline VTKM_EXEC_CONT T Min(const T& x, const T& y)
1808 {
1809  return detail::Min(x, y, typename vtkm::TypeTraits<T>::DimensionalityTag());
1810 }
1811 
1814 
1816 {
1817  return x > lo ? (x < hi ? x : hi) : lo;
1818 }
1819 
1821 {
1822  return x > lo ? (x < hi ? x : hi) : lo;
1823 }
1824 //-----------------------------------------------------------------------------
1825 
1826 //#ifdef VTKM_CUDA
1827 #define VTKM_USE_IEEE_NONFINITE
1828 //#endif
1829 
1830 #ifdef VTKM_USE_IEEE_NONFINITE
1831 
1832 namespace detail
1833 {
1834 
1835 union IEEE754Bits32 {
1836  vtkm::UInt32 bits;
1837  vtkm::Float32 scalar;
1838 };
1839 #define VTKM_NAN_BITS_32 0x7FC00000U
1840 #define VTKM_INF_BITS_32 0x7F800000U
1841 #define VTKM_NEG_INF_BITS_32 0xFF800000U
1842 #define VTKM_EPSILON_32 1e-5f
1843 
1844 union IEEE754Bits64 {
1845  vtkm::UInt64 bits;
1846  vtkm::Float64 scalar;
1847 };
1848 #define VTKM_NAN_BITS_64 0x7FF8000000000000ULL
1849 #define VTKM_INF_BITS_64 0x7FF0000000000000ULL
1850 #define VTKM_NEG_INF_BITS_64 0xFFF0000000000000ULL
1851 #define VTKM_EPSILON_64 1e-9
1852 
1853 template <typename T>
1854 struct FloatLimits;
1855 
1856 template <>
1857 struct FloatLimits<vtkm::Float32>
1858 {
1859  using BitsType = vtkm::detail::IEEE754Bits32;
1860 
1862  static vtkm::Float32 Nan()
1863  {
1864  BitsType nan = { VTKM_NAN_BITS_32 };
1865  return nan.scalar;
1866  }
1867 
1869  static vtkm::Float32 Infinity()
1870  {
1871  BitsType inf = { VTKM_INF_BITS_32 };
1872  return inf.scalar;
1873  }
1874 
1876  static vtkm::Float32 NegativeInfinity()
1877  {
1878  BitsType neginf = { VTKM_NEG_INF_BITS_32 };
1879  return neginf.scalar;
1880  }
1881 
1883  static vtkm::Float32 Epsilon() { return VTKM_EPSILON_32; }
1884 };
1885 
1886 template <int N>
1887 struct FloatLimits<vtkm::Vec<vtkm::Float32, N>>
1888 {
1889  using BitsType = vtkm::detail::IEEE754Bits32;
1890 
1892  static vtkm::Vec<vtkm::Float32, N> Nan()
1893  {
1894  BitsType nan = { VTKM_NAN_BITS_32 };
1895  return vtkm::Vec<vtkm::Float32, N>(nan.scalar);
1896  }
1897 
1899  static vtkm::Vec<vtkm::Float32, N> Infinity()
1900  {
1901  BitsType inf = { VTKM_INF_BITS_32 };
1902  return vtkm::Vec<vtkm::Float32, N>(inf.scalar);
1903  }
1904 
1906  static vtkm::Vec<vtkm::Float32, N> NegativeInfinity()
1907  {
1908  BitsType neginf = { VTKM_NEG_INF_BITS_32 };
1909  return vtkm::Vec<vtkm::Float32, N>(neginf.scalar);
1910  }
1911 
1913  static vtkm::Vec<vtkm::Float32, N> Epsilon()
1914  {
1916  }
1917 };
1918 
1919 template <>
1920 struct FloatLimits<vtkm::Float64>
1921 {
1922  using BitsType = vtkm::detail::IEEE754Bits64;
1923 
1925  static vtkm::Float64 Nan()
1926  {
1927  BitsType nan = { VTKM_NAN_BITS_64 };
1928  return nan.scalar;
1929  }
1930 
1932  static vtkm::Float64 Infinity()
1933  {
1934  BitsType inf = { VTKM_INF_BITS_64 };
1935  return inf.scalar;
1936  }
1937 
1939  static vtkm::Float64 NegativeInfinity()
1940  {
1941  BitsType neginf = { VTKM_NEG_INF_BITS_64 };
1942  return neginf.scalar;
1943  }
1944 
1946  static vtkm::Float64 Epsilon() { return VTKM_EPSILON_64; }
1947 };
1948 
1949 template <int N>
1950 struct FloatLimits<vtkm::Vec<vtkm::Float64, N>>
1951 {
1952  using BitsType = vtkm::detail::IEEE754Bits64;
1953 
1955  static vtkm::Vec<vtkm::Float64, N> Nan()
1956  {
1957  BitsType nan = { VTKM_NAN_BITS_64 };
1958  return vtkm::Vec<vtkm::Float64, N>(nan.scalar);
1959  }
1960 
1962  static vtkm::Vec<vtkm::Float64, N> Infinity()
1963  {
1964  BitsType inf = { VTKM_INF_BITS_64 };
1965  return vtkm::Vec<vtkm::Float64, N>(inf.scalar);
1966  }
1967 
1969  static vtkm::Vec<vtkm::Float64, N> NegativeInfinity()
1970  {
1971  BitsType neginf = { VTKM_NEG_INF_BITS_64 };
1972  return vtkm::Vec<vtkm::Float64, N>(neginf.scalar);
1973  }
1974 
1976  static vtkm::Vec<vtkm::Float64, N> Epsilon()
1977  {
1979  }
1980 };
1981 
1982 #undef VTKM_NAN_BITS_32
1983 #undef VTKM_INF_BITS_32
1984 #undef VTKM_NEG_INF_BITS_32
1985 #undef VTKM_EPSILON_32
1986 #undef VTKM_NAN_BITS_64
1987 #undef VTKM_INF_BITS_64
1988 #undef VTKM_NEG_INF_BITS_64
1989 #undef VTKM_EPSILON_64
1990 
1991 } // namespace detail
1992 
1995 template <typename T>
1996 static inline VTKM_EXEC_CONT T Nan()
1997 {
1998  return detail::FloatLimits<T>::Nan();
1999 }
2000 
2003 template <typename T>
2004 static inline VTKM_EXEC_CONT T Infinity()
2005 {
2006  return detail::FloatLimits<T>::Infinity();
2007 }
2008 
2011 template <typename T>
2012 static inline VTKM_EXEC_CONT T NegativeInfinity()
2013 {
2014  return detail::FloatLimits<T>::NegativeInfinity();
2015 }
2016 
2020 template <typename T>
2021 static inline VTKM_EXEC_CONT T Epsilon()
2022 {
2023  return detail::FloatLimits<T>::Epsilon();
2024 }
2025 
2026 #else // !VTKM_USE_IEEE_NONFINITE
2027 
2030 template <typename T>
2031 static inline VTKM_EXEC_CONT T Nan()
2032 {
2033  return std::numeric_limits<T>::quiet_NaN();
2034 }
2035 
2038 template <typename T>
2039 static inline VTKM_EXEC_CONT T Infinity()
2040 {
2041  return std::numeric_limits<T>::infinity();
2042 }
2043 
2046 template <typename T>
2047 static inline VTKM_EXEC_CONT T NegativeInfinity()
2048 {
2049  return -std::numeric_limits<T>::infinity();
2050 }
2051 
2055 template <typename T>
2056 static inline VTKM_EXEC_CONT T Epsilon()
2057 {
2058  return std::numeric_limits<T>::epsilon();
2059 }
2060 #endif // !VTKM_USE_IEEE_NONFINITE
2061 
2064 static inline VTKM_EXEC_CONT vtkm::Float32 Nan32()
2065 {
2066  return vtkm::Nan<vtkm::Float32>();
2067 }
2068 static inline VTKM_EXEC_CONT vtkm::Float64 Nan64()
2069 {
2070  return vtkm::Nan<vtkm::Float64>();
2071 }
2072 
2075 static inline VTKM_EXEC_CONT vtkm::Float32 Infinity32()
2076 {
2077  return vtkm::Infinity<vtkm::Float32>();
2078 }
2079 static inline VTKM_EXEC_CONT vtkm::Float64 Infinity64()
2080 {
2081  return vtkm::Infinity<vtkm::Float64>();
2082 }
2083 
2086 static inline VTKM_EXEC_CONT vtkm::Float32 NegativeInfinity32()
2087 {
2088  return vtkm::NegativeInfinity<vtkm::Float32>();
2089 }
2090 static inline VTKM_EXEC_CONT vtkm::Float64 NegativeInfinity64()
2091 {
2092  return vtkm::NegativeInfinity<vtkm::Float64>();
2093 }
2094 
2098 static inline VTKM_EXEC_CONT vtkm::Float32 Epsilon32()
2099 {
2100  return vtkm::Epsilon<vtkm::Float32>();
2101 }
2102 static inline VTKM_EXEC_CONT vtkm::Float64 Epsilon64()
2103 {
2104  return vtkm::Epsilon<vtkm::Float64>();
2105 }
2106 
2107 //-----------------------------------------------------------------------------
2110 template <typename T>
2111 static inline VTKM_EXEC_CONT bool IsNan(T x)
2112 {
2113 #ifndef VTKM_CUDA
2114  using std::isnan;
2115 #endif
2116  return (isnan(x) != 0);
2117 }
2118 
2121 template <typename T>
2122 static inline VTKM_EXEC_CONT bool IsInf(T x)
2123 {
2124 #ifndef VTKM_CUDA
2125  using std::isinf;
2126 #endif
2127  return (isinf(x) != 0);
2128 }
2129 
2132 template <typename T>
2133 static inline VTKM_EXEC_CONT bool IsFinite(T x)
2134 {
2135 #ifndef VTKM_CUDA
2136  using std::isfinite;
2137 #endif
2138  return (isfinite(x) != 0);
2139 }
2140 
2141 //-----------------------------------------------------------------------------
2144 
2146 {
2147 #ifdef VTKM_CUDA
2148  return VTKM_CUDA_MATH_FUNCTION_32(ceil)(x);
2149 #else
2150  return std::ceil(x);
2151 #endif
2152 }
2153 
2155 {
2156 #ifdef VTKM_CUDA
2157  return VTKM_CUDA_MATH_FUNCTION_64(ceil)(x);
2158 #else
2159  return std::ceil(x);
2160 #endif
2161 }
2162 template <typename T>
2163 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Ceil(const T& x)
2164 {
2165  using RT = typename detail::FloatingPointReturnType<T>::Type;
2166  return vtkm::Ceil(static_cast<RT>(x));
2167 }
2168 template <typename T, vtkm::IdComponent N>
2170  const vtkm::Vec<T, N>& x)
2171 {
2173  for (vtkm::IdComponent index = 0; index < N; index++)
2174  {
2175  result[index] = vtkm::Ceil(x[index]);
2176  }
2177  return result;
2178 }
2179 template <typename T>
2181  const vtkm::Vec<T, 4>& x)
2182 {
2184  vtkm::Ceil(x[0]), vtkm::Ceil(x[1]), vtkm::Ceil(x[2]), vtkm::Ceil(x[3]));
2185 }
2186 template <typename T>
2188  const vtkm::Vec<T, 3>& x)
2189 {
2191  vtkm::Ceil(x[0]), vtkm::Ceil(x[1]), vtkm::Ceil(x[2]));
2192 }
2193 template <typename T>
2195  const vtkm::Vec<T, 2>& x)
2196 {
2198  vtkm::Ceil(x[1]));
2199 }
2200 
2203 
2205 {
2206 #ifdef VTKM_CUDA
2207  return VTKM_CUDA_MATH_FUNCTION_32(floor)(x);
2208 #else
2209  return std::floor(x);
2210 #endif
2211 }
2212 
2214 {
2215 #ifdef VTKM_CUDA
2216  return VTKM_CUDA_MATH_FUNCTION_64(floor)(x);
2217 #else
2218  return std::floor(x);
2219 #endif
2220 }
2221 template <typename T>
2222 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Floor(const T& x)
2223 {
2224  using RT = typename detail::FloatingPointReturnType<T>::Type;
2225  return vtkm::Floor(static_cast<RT>(x));
2226 }
2227 template <typename T, vtkm::IdComponent N>
2229  const vtkm::Vec<T, N>& x)
2230 {
2232  for (vtkm::IdComponent index = 0; index < N; index++)
2233  {
2234  result[index] = vtkm::Floor(x[index]);
2235  }
2236  return result;
2237 }
2238 template <typename T>
2240  const vtkm::Vec<T, 4>& x)
2241 {
2243  vtkm::Floor(x[0]), vtkm::Floor(x[1]), vtkm::Floor(x[2]), vtkm::Floor(x[3]));
2244 }
2245 template <typename T>
2247  const vtkm::Vec<T, 3>& x)
2248 {
2250  vtkm::Floor(x[0]), vtkm::Floor(x[1]), vtkm::Floor(x[2]));
2251 }
2252 template <typename T>
2254  const vtkm::Vec<T, 2>& x)
2255 {
2257  vtkm::Floor(x[1]));
2258 }
2259 
2262 
2264 {
2265 #ifdef VTKM_CUDA
2266  return VTKM_CUDA_MATH_FUNCTION_32(round)(x);
2267 #else
2268  return std::round(x);
2269 #endif
2270 }
2271 
2273 {
2274 #ifdef VTKM_CUDA
2275  return VTKM_CUDA_MATH_FUNCTION_64(round)(x);
2276 #else
2277  return std::round(x);
2278 #endif
2279 }
2280 template <typename T>
2281 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Round(const T& x)
2282 {
2283  using RT = typename detail::FloatingPointReturnType<T>::Type;
2284  return vtkm::Round(static_cast<RT>(x));
2285 }
2286 template <typename T, vtkm::IdComponent N>
2288  const vtkm::Vec<T, N>& x)
2289 {
2291  for (vtkm::IdComponent index = 0; index < N; index++)
2292  {
2293  result[index] = vtkm::Round(x[index]);
2294  }
2295  return result;
2296 }
2297 template <typename T>
2299  const vtkm::Vec<T, 4>& x)
2300 {
2302  vtkm::Round(x[0]), vtkm::Round(x[1]), vtkm::Round(x[2]), vtkm::Round(x[3]));
2303 }
2304 template <typename T>
2306  const vtkm::Vec<T, 3>& x)
2307 {
2309  vtkm::Round(x[0]), vtkm::Round(x[1]), vtkm::Round(x[2]));
2310 }
2311 template <typename T>
2313  const vtkm::Vec<T, 2>& x)
2314 {
2316  vtkm::Round(x[1]));
2317 }
2318 
2319 //-----------------------------------------------------------------------------
2326 {
2327 #ifdef VTKM_CUDA
2328  return VTKM_CUDA_MATH_FUNCTION_32(fmod)(x, y);
2329 #else
2330  return std::fmod(x, y);
2331 #endif
2332 }
2334 {
2335 #ifdef VTKM_CUDA
2336  return VTKM_CUDA_MATH_FUNCTION_64(fmod)(x, y);
2337 #else
2338  return std::fmod(x, y);
2339 #endif
2340 }
2341 
2348 #ifdef VTKM_MSVC
2349 template <typename T>
2350 static inline VTKM_EXEC_CONT T Remainder(T numerator, T denominator)
2351 {
2352  T quotient = vtkm::Round(numerator / denominator);
2353  return numerator - quotient * denominator;
2354 }
2355 #else // !VTKM_MSVC
2356 static inline VTKM_EXEC_CONT vtkm::Float32 Remainder(vtkm::Float32 x, vtkm::Float32 y)
2357 {
2358 #ifdef VTKM_CUDA
2359  return VTKM_CUDA_MATH_FUNCTION_32(remainder)(x, y);
2360 #else
2361  return std::remainder(x, y);
2362 #endif
2363 }
2364 static inline VTKM_EXEC_CONT vtkm::Float64 Remainder(vtkm::Float64 x, vtkm::Float64 y)
2365 {
2366 #ifdef VTKM_CUDA
2367  return VTKM_CUDA_MATH_FUNCTION_64(remainder)(x, y);
2368 #else
2369  return std::remainder(x, y);
2370 #endif
2371 }
2372 #endif // !VTKM_MSVC
2373 
2378 template <typename QType>
2379 static inline VTKM_EXEC_CONT vtkm::Float32 RemainderQuotient(vtkm::Float32 numerator,
2380  vtkm::Float32 denominator,
2381  QType& quotient)
2382 {
2383  int iQuotient;
2384  // See: https://github.com/ROCm-Developer-Tools/HIP/issues/2169
2385 #if defined(VTKM_CUDA) || defined(VTKM_HIP)
2386  const vtkm::Float32 result =
2387  VTKM_CUDA_MATH_FUNCTION_32(remquo)(numerator, denominator, &iQuotient);
2388 #else
2389  const vtkm::Float32 result = std::remquo(numerator, denominator, &iQuotient);
2390 #endif
2391  quotient = static_cast<QType>(iQuotient);
2392  return result;
2393 }
2394 template <typename QType>
2395 static inline VTKM_EXEC_CONT vtkm::Float64 RemainderQuotient(vtkm::Float64 numerator,
2396  vtkm::Float64 denominator,
2397  QType& quotient)
2398 {
2399  int iQuotient;
2400 #ifdef VTKM_CUDA
2401  const vtkm::Float64 result =
2402  VTKM_CUDA_MATH_FUNCTION_64(remquo)(numerator, denominator, &iQuotient);
2403 #else
2404  const vtkm::Float64 result = std::remquo(numerator, denominator, &iQuotient);
2405 #endif
2406  quotient = static_cast<QType>(iQuotient);
2407  return result;
2408 }
2409 
2413 static inline VTKM_EXEC_CONT vtkm::Float32 ModF(vtkm::Float32 x, vtkm::Float32& integral)
2414 {
2415  // See: https://github.com/ROCm-Developer-Tools/HIP/issues/2169
2416 #if defined(VTKM_CUDA) || defined(VTKM_HIP)
2417  return VTKM_CUDA_MATH_FUNCTION_32(modf)(x, &integral);
2418 #else
2419  return std::modf(x, &integral);
2420 #endif
2421 }
2422 static inline VTKM_EXEC_CONT vtkm::Float64 ModF(vtkm::Float64 x, vtkm::Float64& integral)
2423 {
2424 #if defined(VTKM_CUDA)
2425  return VTKM_CUDA_MATH_FUNCTION_64(modf)(x, &integral);
2426 #else
2427  return std::modf(x, &integral);
2428 #endif
2429 }
2430 
2431 //-----------------------------------------------------------------------------
2435 static inline VTKM_EXEC_CONT vtkm::Int32 Abs(vtkm::Int32 x)
2436 {
2437  return abs(x);
2438 }
2439 static inline VTKM_EXEC_CONT vtkm::Int64 Abs(vtkm::Int64 x)
2440 {
2441 #if VTKM_SIZE_LONG == 8
2442  return labs(x);
2443 #elif VTKM_SIZE_LONG_LONG == 8
2444  return llabs(x);
2445 #else
2446 #error Unknown size of Int64.
2447 #endif
2448 }
2449 static inline VTKM_EXEC_CONT vtkm::Float32 Abs(vtkm::Float32 x)
2450 {
2451 #ifdef VTKM_CUDA
2452  return VTKM_CUDA_MATH_FUNCTION_32(fabs)(x);
2453 #else
2454  return std::fabs(x);
2455 #endif
2456 }
2457 static inline VTKM_EXEC_CONT vtkm::Float64 Abs(vtkm::Float64 x)
2458 {
2459 #ifdef VTKM_CUDA
2460  return VTKM_CUDA_MATH_FUNCTION_64(fabs)(x);
2461 #else
2462  return std::fabs(x);
2463 #endif
2464 }
2465 template <typename T>
2466 static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Abs(T x)
2467 {
2468 #ifdef VTKM_CUDA
2469  return VTKM_CUDA_MATH_FUNCTION_64(fabs)(static_cast<vtkm::Float64>(x));
2470 #else
2471  return std::fabs(static_cast<vtkm::Float64>(x));
2472 #endif
2473 }
2474 template <typename T, vtkm::IdComponent N>
2475 static inline VTKM_EXEC_CONT vtkm::Vec<T, N> Abs(const vtkm::Vec<T, N>& x)
2476 {
2477  vtkm::Vec<T, N> result;
2478  for (vtkm::IdComponent index = 0; index < N; index++)
2479  {
2480  result[index] = vtkm::Abs(x[index]);
2481  }
2482  return result;
2483 }
2484 template <typename T>
2485 static inline VTKM_EXEC_CONT vtkm::Vec<T, 4> Abs(const vtkm::Vec<T, 4>& x)
2486 {
2487  return vtkm::Vec<T, 4>(vtkm::Abs(x[0]), vtkm::Abs(x[1]), vtkm::Abs(x[2]), vtkm::Abs(x[3]));
2488 }
2489 template <typename T>
2490 static inline VTKM_EXEC_CONT vtkm::Vec<T, 3> Abs(const vtkm::Vec<T, 3>& x)
2491 {
2492  return vtkm::Vec<T, 3>(vtkm::Abs(x[0]), vtkm::Abs(x[1]), vtkm::Abs(x[2]));
2493 }
2494 template <typename T>
2495 static inline VTKM_EXEC_CONT vtkm::Vec<T, 2> Abs(const vtkm::Vec<T, 2>& x)
2496 {
2497  return vtkm::Vec<T, 2>(vtkm::Abs(x[0]), vtkm::Abs(x[1]));
2498 }
2499 
2502 static inline VTKM_EXEC_CONT vtkm::Int32 SignBit(vtkm::Float32 x)
2503 {
2504 #ifndef VTKM_CUDA
2505  using std::signbit;
2506 #endif
2507  return static_cast<vtkm::Int32>(signbit(x));
2508 }
2509 static inline VTKM_EXEC_CONT vtkm::Int32 SignBit(vtkm::Float64 x)
2510 {
2511 #ifndef VTKM_CUDA
2512  using std::signbit;
2513 #endif
2514  return static_cast<vtkm::Int32>(signbit(x));
2515 }
2516 
2519 static inline VTKM_EXEC_CONT bool IsNegative(vtkm::Float32 x)
2520 {
2521  return (vtkm::SignBit(x) != 0);
2522 }
2523 static inline VTKM_EXEC_CONT bool IsNegative(vtkm::Float64 x)
2524 {
2525  return (vtkm::SignBit(x) != 0);
2526 }
2527 
2531 static inline VTKM_EXEC_CONT vtkm::Float32 CopySign(vtkm::Float32 x, vtkm::Float32 y)
2532 {
2533 #ifdef VTKM_CUDA
2534  return VTKM_CUDA_MATH_FUNCTION_32(copysign)(x, y);
2535 #else
2536  return std::copysign(x, y);
2537 #endif
2538 }
2539 static inline VTKM_EXEC_CONT vtkm::Float64 CopySign(vtkm::Float64 x, vtkm::Float64 y)
2540 {
2541 #ifdef VTKM_CUDA
2542  return VTKM_CUDA_MATH_FUNCTION_64(copysign)(x, y);
2543 #else
2544  return std::copysign(x, y);
2545 #endif
2546 }
2547 
2548 template <typename T, vtkm::IdComponent N>
2549 static inline VTKM_EXEC_CONT vtkm::Vec<T, N> CopySign(const vtkm::Vec<T, N>& x,
2550  const vtkm::Vec<T, N>& y)
2551 {
2552  vtkm::Vec<T, N> result;
2553  for (vtkm::IdComponent index = 0; index < N; index++)
2554  {
2555  result[index] = vtkm::CopySign(x[index], y[index]);
2556  }
2557  return result;
2558 }
2559 
2562 
2564 {
2565  // See: https://github.com/ROCm-Developer-Tools/HIP/issues/2169
2566 #if defined(VTKM_CUDA) || defined(VTKM_HIP)
2567  return VTKM_CUDA_MATH_FUNCTION_32(frexp)(x, exponent);
2568 #else
2569  return std::frexp(x, exponent);
2570 #endif
2571 }
2572 
2574 {
2575 #ifdef VTKM_CUDA
2576  return VTKM_CUDA_MATH_FUNCTION_64(frexp)(x, exponent);
2577 #else
2578  return std::frexp(x, exponent);
2579 #endif
2580 }
2581 
2583 {
2584 #ifdef VTKM_CUDA
2585  return VTKM_CUDA_MATH_FUNCTION_32(ldexp)(x, exponent);
2586 #else
2587  return std::ldexp(x, exponent);
2588 #endif
2589 }
2590 
2592 {
2593 #ifdef VTKM_CUDA
2594  return VTKM_CUDA_MATH_FUNCTION_64(ldexp)(x, exponent);
2595 #else
2596  return std::ldexp(x, exponent);
2597 #endif
2598 }
2599 
2601 // Float distance.
2602 // See: https://randomascii.wordpress.com/2012/01/23/stupid-float-tricks-2/ for why this works.
2603 
2604 namespace detail
2605 {
2606 
2607 inline VTKM_EXEC_CONT vtkm::UInt64 FloatDistancePositive(vtkm::Float64 x, vtkm::Float64 y)
2608 {
2609  VTKM_ASSERT(x >= 0);
2610  VTKM_ASSERT(y >= 0);
2611 
2612  // Note that:
2613  // int64_t xi = *reinterpret_cast<int64_t*>(&x);
2614  // int64_t yi = *reinterpret_cast<int64_t*>(&y);
2615  // also works (usually), but generates warnings because it is technically undefined behavior
2616  // according to the C++ standard.
2617  // Good option to have if we get compile errors off memcpy or don't want to #include <cstring> though.
2618  // At least on gcc, both versions generate the same assembly.
2619  vtkm::UInt64 xi;
2620  vtkm::UInt64 yi;
2621  memcpy(&xi, &x, sizeof(vtkm::UInt64));
2622  memcpy(&yi, &y, sizeof(vtkm::UInt64));
2623  if (yi > xi) {
2624  return yi - xi;
2625  }
2626  return xi - yi;
2627 }
2628 
2629 
2630 inline VTKM_EXEC_CONT vtkm::UInt64 FloatDistancePositive(vtkm::Float32 x, vtkm::Float32 y)
2631 {
2632  VTKM_ASSERT(x >= 0);
2633  VTKM_ASSERT(y >= 0);
2634 
2635  vtkm::UInt32 xi_32;
2636  vtkm::UInt32 yi_32;
2637  memcpy(&xi_32, &x, sizeof(vtkm::UInt32));
2638  memcpy(&yi_32, &y, sizeof(vtkm::UInt32));
2639  vtkm::UInt64 xi = xi_32;
2640  vtkm::UInt64 yi = yi_32;
2641  if (yi > xi) {
2642  return yi - xi;
2643  }
2644  return xi - yi;
2645 }
2646 
2647 } // namespace detail
2648 
2650 {
2651  static_assert(sizeof(vtkm::Float64) == sizeof(vtkm::UInt64), "vtkm::Float64 is incorrect size.");
2652  static_assert(std::numeric_limits<vtkm::Float64>::has_denorm == std::denorm_present, "FloatDistance presumes the floating-point type has subnormal numbers.");
2653 
2654  if (!vtkm::IsFinite(x) || !vtkm::IsFinite(y)) {
2655  return 0xFFFFFFFFFFFFFFFFL;
2656  }
2657 
2658  // Signed zero is the sworn enemy of this process.
2659  if (y == 0) {
2660  y = vtkm::Abs(y);
2661  }
2662  if (x == 0) {
2663  x = vtkm::Abs(x);
2664  }
2665 
2666  if ( (x < 0 && y >= 0) || (x >= 0 && y < 0) )
2667  {
2668  vtkm::UInt64 dx, dy;
2669  if (x < 0) {
2670  dy = detail::FloatDistancePositive(0.0, y);
2671  dx = detail::FloatDistancePositive(0.0, -x);
2672  }
2673  else {
2674  dy = detail::FloatDistancePositive(0.0, -y);
2675  dx = detail::FloatDistancePositive(0.0, x);
2676  }
2677 
2678  return dx + dy;
2679  }
2680 
2681  if (x < 0 && y < 0) {
2682  return detail::FloatDistancePositive(-x, -y);
2683  }
2684 
2685  return detail::FloatDistancePositive(x, y);
2686 }
2687 
2689 {
2690  static_assert(sizeof(vtkm::Float32) == sizeof(vtkm::Int32), "vtkm::Float32 is incorrect size.");
2691  static_assert(std::numeric_limits<vtkm::Float32>::has_denorm == std::denorm_present, "FloatDistance presumes the floating-point type has subnormal numbers.");
2692 
2693  if (!vtkm::IsFinite(x) || !vtkm::IsFinite(y)) {
2694  return 0xFFFFFFFFFFFFFFFFL;
2695  }
2696 
2697  if (y == 0) {
2698  y = vtkm::Abs(y);
2699  }
2700  if (x == 0) {
2701  x = vtkm::Abs(x);
2702  }
2703 
2704  if ( (x < 0 && y >= 0) || (x >= 0 && y < 0) )
2705  {
2706  vtkm::UInt64 dx, dy;
2707  if (x < 0) {
2708  dy = detail::FloatDistancePositive(0.0f, y);
2709  dx = detail::FloatDistancePositive(0.0f, -x);
2710  }
2711  else {
2712  dy = detail::FloatDistancePositive(0.0f, -y);
2713  dx = detail::FloatDistancePositive(0.0f, x);
2714  }
2715  return dx + dy;
2716  }
2717 
2718  if (x < 0 && y < 0) {
2719  return detail::FloatDistancePositive(-x, -y);
2720  }
2721 
2722  return detail::FloatDistancePositive(x, y);
2723 }
2724 
2725 // Computes ab - cd.
2726 // See: https://pharr.org/matt/blog/2019/11/03/difference-of-floats.html
2727 template<typename T>
2728 inline VTKM_EXEC_CONT T DifferenceOfProducts(T a, T b, T c, T d)
2729 {
2730  T cd = c * d;
2731  T err = std::fma(-c, d, cd);
2732  T dop = std::fma(a, b, -cd);
2733  return dop + err;
2734 }
2735 
2736 // Solves ax² + bx + c = 0.
2737 // Only returns the real roots.
2738 // If there are real roots, the first element of the pair is <= the second.
2739 // If there are no real roots, both elements are NaNs.
2740 // The error should be at most 3 ulps.
2741 template<typename T>
2743 {
2744  if (a == 0)
2745  {
2746  if (b == 0)
2747  {
2748  if (c == 0)
2749  {
2750  // A degenerate case. All real numbers are roots; hopefully this arbitrary decision interacts gracefully with use.
2751  return vtkm::Vec<T,2>(0,0);
2752  }
2753  else
2754  {
2755  return vtkm::Vec<T,2>(vtkm::Nan<T>(), vtkm::Nan<T>());
2756  }
2757  }
2758  return vtkm::Vec<T,2>(-c/b, -c/b);
2759  }
2760  T delta = DifferenceOfProducts(b, b, 4*a, c);
2761  if (delta < 0)
2762  {
2763  return vtkm::Vec<T,2>(vtkm::Nan<T>(), vtkm::Nan<T>());
2764  }
2765 
2766  T q = -(b + vtkm::CopySign(vtkm::Sqrt(delta), b)) / 2;
2767  T r0 = q / a;
2768  T r1 = c / q;
2769  if (r0 < r1)
2770  {
2771  return vtkm::Vec<T,2>(r0, r1);
2772  }
2773  return vtkm::Vec<T,2>(r1, r0);
2774 }
2775 
2778 
2781 #ifdef VTKM_CUDA_DEVICE_PASS
2782 // Need to explicitly mark this as __device__ since __ffs is device only.
2783 inline __device__
2785 {
2786  // Output is [0,32], with ffs(0) == 0
2787  return __ffs(static_cast<int>(word));
2788 }
2789 #else // CUDA_DEVICE_PASS
2790 inline VTKM_EXEC_CONT
2792 {
2793 # if defined(VTKM_GCC) || defined(VTKM_CLANG)
2794 
2795  // Output is [0,32], with ffs(0) == 0
2796  return __builtin_ffs(static_cast<int>(word));
2797 
2798 # elif defined(VTKM_MSVC)
2799 
2800  // Output is [0, 31], check return code to see if bits are set:
2801  vtkm::UInt32 firstSet;
2802  return _BitScanForward(reinterpret_cast<DWORD*>(&firstSet), word) != 0
2803  ? static_cast<vtkm::Int32>(firstSet + 1) : 0;
2804 
2805 # elif defined(VTKM_ICC)
2806 
2807  // Output is [0, 31], undefined if word is 0.
2808  return word != 0 ? _bit_scan_forward(word) + 1 : 0;
2809 
2810 # else
2811 
2812  // Naive implementation:
2813  if (word == 0)
2814  {
2815  return 0;
2816  }
2817 
2818  vtkm::Int32 bit = 1;
2819  while ((word & 0x1) == 0)
2820  {
2821  word >>= 1;
2822  ++bit;
2823  }
2824  return bit;
2825 
2826 # endif
2827 }
2828 #endif // CUDA_DEVICE_PASS
2829 
2832 #ifdef VTKM_CUDA_DEVICE_PASS
2833 // Need to explicitly mark this as __device__ since __ffsll is device only.
2834 inline __device__
2835 vtkm::Int32 FindFirstSetBit(vtkm::UInt64 word)
2836 {
2837 
2838  // Output is [0,64], with ffs(0) == 0
2839  return __ffsll(static_cast<long long int>(word));
2840 }
2841 #else // CUDA_DEVICE_PASS
2842 inline VTKM_EXEC_CONT
2843 vtkm::Int32 FindFirstSetBit(vtkm::UInt64 word)
2844 {
2845 # if defined(VTKM_GCC) || defined(VTKM_CLANG) || defined(VTKM_ICC)
2846 
2847  // Output is [0,64], with ffs(0) == 0
2848  return __builtin_ffsll(static_cast<long long int>(word));
2849 
2850 # elif defined(VTKM_MSVC)
2851 
2852  // Output is [0, 63], check return code to see if bits are set:
2853  vtkm::UInt32 firstSet;
2854  return _BitScanForward64(reinterpret_cast<DWORD*>(&firstSet), word) != 0
2855  ? static_cast<vtkm::Int32>(firstSet + 1) : 0;
2856 
2857 # else
2858 
2859  // Naive implementation:
2860  if (word == 0)
2861  {
2862  return 0;
2863  }
2864 
2865  vtkm::Int32 bit = 1;
2866  while ((word & 0x1) == 0)
2867  {
2868  word >>= 1;
2869  ++bit;
2870  }
2871  return bit;
2872 
2873 # endif
2874 }
2875 #endif // CUDA_DEVICE_PASS
2876 
2878 #ifdef VTKM_CUDA_DEVICE_PASS
2879 // Need to explicitly mark this as __device__ since __popc is device only.
2880 inline __device__
2882 {
2883  return __popc(word);
2884 }
2885 #else // CUDA_DEVICE_PASS
2886 inline VTKM_EXEC_CONT
2888 {
2889 # if defined(VTKM_GCC) || defined(VTKM_CLANG)
2890 
2891  return __builtin_popcount(word);
2892 
2893 # elif defined(VTKM_MSVC) && !defined(_M_ARM64)
2894 
2895  return static_cast<vtkm::Int32>(__popcnt(word));
2896 
2897 # elif defined(VTKM_ICC)
2898 
2899  return _popcnt32(static_cast<int>(word));
2900 
2901 # else
2902 
2903  // Naive implementation:
2904  vtkm::Int32 bits = 0;
2905  while (word)
2906  {
2907  if (word & 0x1)
2908  {
2909  ++bits;
2910  }
2911  word >>= 1;
2912  }
2913  return bits;
2914 
2915 # endif
2916 }
2917 #endif // CUDA_DEVICE_PASS
2918 
2920 #ifdef VTKM_CUDA_DEVICE_PASS
2921 // Need to explicitly mark this as __device__ since __popcll is device only.
2922 inline __device__
2923 vtkm::Int32 CountSetBits(vtkm::UInt64 word)
2924 {
2925  return __popcll(word);
2926 }
2927 #else // CUDA_DEVICE_PASS
2928 inline VTKM_EXEC_CONT
2929 vtkm::Int32 CountSetBits(vtkm::UInt64 word)
2930 {
2931 # if defined(VTKM_GCC) || defined(VTKM_CLANG)
2932 
2933  return __builtin_popcountll(word);
2934 
2935 # elif defined(VTKM_MSVC) && !defined(_M_ARM64)
2936 
2937  return static_cast<vtkm::Int32>(__popcnt64(word));
2938 
2939 # elif defined(VTKM_ICC)
2940 
2941  return _popcnt64(static_cast<vtkm::Int64>(word));
2942 
2943 # else
2944 
2945  // Naive implementation:
2946  vtkm::Int32 bits = 0;
2947  while (word)
2948  {
2949  if (word & 0x1)
2950  {
2951  ++bits;
2952  }
2953  word >>= 1;
2954  }
2955  return bits;
2956 
2957 # endif
2958 }
2959 #endif // CUDA_DEVICE_PASS
2960 
2961 } // namespace vtkm
2962 // clang-format on
2963 
2964 #endif //vtk_m_Math_h
vtkm::ASinH
VTKM_EXEC_CONT vtkm::Float32 ASinH(vtkm::Float32 x)
Compute the hyperbolic arc sine of x.
Definition: Math.h:761
vtkm::Sqrt
VTKM_EXEC_CONT vtkm::Float32 Sqrt(vtkm::Float32 x)
Compute the square root of x.
Definition: Math.h:958
VTKM_NAN_BITS_64
#define VTKM_NAN_BITS_64
Definition: Math.h:1848
vtkm::ExpM1
VTKM_EXEC_CONT vtkm::Float32 ExpM1(vtkm::Float32 x)
Computes (e**x) - 1, the of base-e exponental of x then minus 1.
Definition: Math.h:1331
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
VTKM_CUDA_MATH_FUNCTION_64
#define VTKM_CUDA_MATH_FUNCTION_64(func)
Definition: Math.h:43
vtkm::Cos
VTKM_EXEC_CONT vtkm::Float32 Cos(vtkm::Float32 x)
Compute the cosine of x.
Definition: Math.h:269
vtkm::Ceil
VTKM_EXEC_CONT vtkm::Float32 Ceil(vtkm::Float32 x)
Round x to the smallest integer value not less than x.
Definition: Math.h:2145
vtkm::Round
VTKM_EXEC_CONT vtkm::Float32 Round(vtkm::Float32 x)
Round x to the nearest integral value.
Definition: Math.h:2263
VTKM_INF_BITS_64
#define VTKM_INF_BITS_64
Definition: Math.h:1849
Types.h
VTKM_ASSERT
#define VTKM_ASSERT(condition)
Definition: Assert.h:43
VTKM_EPSILON_32
#define VTKM_EPSILON_32
Definition: Math.h:1842
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::FloatDistance
VTKM_EXEC_CONT vtkm::UInt64 FloatDistance(vtkm::Float64 x, vtkm::Float64 y)
Definition: Math.h:2649
VTKM_NEG_INF_BITS_64
#define VTKM_NEG_INF_BITS_64
Definition: Math.h:1850
vtkm::Log1P
VTKM_EXEC_CONT vtkm::Float32 Log1P(vtkm::Float32 x)
Computes the value of log(1+x) accurately for very small values of x.
Definition: Math.h:1632
vtkm::CosH
VTKM_EXEC_CONT vtkm::Float32 CosH(vtkm::Float32 x)
Compute the hyperbolic cosine of x.
Definition: Math.h:643
vtkm::Cbrt
VTKM_EXEC_CONT vtkm::Float32 Cbrt(vtkm::Float32 x)
Compute the cube root of x.
Definition: Math.h:1085
vtkm::Clamp
VTKM_EXEC_CONT vtkm::Float32 Clamp(vtkm::Float32 x, vtkm::Float32 lo, vtkm::Float32 hi)
Clamp x to the given range.
Definition: Math.h:1815
vtkm::ACosH
VTKM_EXEC_CONT vtkm::Float32 ACosH(vtkm::Float32 x)
Compute the hyperbolic arc cosine of x.
Definition: Math.h:820
vtkm::Vec
class VTKM_ALWAYS_EXPORT Vec
Definition: Types.h:319
vtkm::Sin
VTKM_EXEC_CONT vtkm::Float32 Sin(vtkm::Float32 x)
Compute the sine of x.
Definition: Math.h:210
vtkm::Tan
VTKM_EXEC_CONT vtkm::Float32 Tan(vtkm::Float32 x)
Compute the tangent of x.
Definition: Math.h:328
vtkm::Log2
VTKM_EXEC_CONT vtkm::Float32 Log2(vtkm::Float32 x)
Computes the logarithm base 2 of x.
Definition: Math.h:1514
vtkm::Floor
VTKM_EXEC_CONT vtkm::Float32 Floor(vtkm::Float32 x)
Round x to the largest integer value not greater than x.
Definition: Math.h:2204
vtkm::ASin
VTKM_EXEC_CONT vtkm::Float32 ASin(vtkm::Float32 x)
Compute the arc sine of x.
Definition: Math.h:387
TypeTraits.h
vtkm::Frexp
VTKM_EXEC_CONT vtkm::Float32 Frexp(vtkm::Float32 x, vtkm::Int32 *exponent)
Decompose floating poing value.
Definition: Math.h:2563
vtkm::Exp
VTKM_EXEC_CONT vtkm::Float32 Exp(vtkm::Float32 x)
Computes e**x, the base-e exponential of x.
Definition: Math.h:1212
VTKM_NAN_BITS_32
#define VTKM_NAN_BITS_32
Definition: Math.h:1839
vtkm::Vec< T, 4 >
Definition: Types.h:1093
vtkm::SinH
VTKM_EXEC_CONT vtkm::Float32 SinH(vtkm::Float32 x)
Compute the hyperbolic sine of x.
Definition: Math.h:584
vtkm::Vec< T, 2 >
Definition: Types.h:859
vtkm::FindFirstSetBit
VTKM_EXEC_CONT vtkm::Int32 FindFirstSetBit(vtkm::UInt32 word)
Bitwise operations.
Definition: Math.h:2791
vtkm::DifferenceOfProducts
VTKM_EXEC_CONT T DifferenceOfProducts(T a, T b, T c, T d)
Definition: Math.h:2728
vtkm::Log10
VTKM_EXEC_CONT vtkm::Float32 Log10(vtkm::Float32 x)
Computes the logarithm base 10 of x.
Definition: Math.h:1573
vtkm::QuadraticRoots
VTKM_EXEC_CONT vtkm::Vec< T, 2 > QuadraticRoots(T a, T b, T c)
Definition: Math.h:2742
VTKM_INF_BITS_32
#define VTKM_INF_BITS_32
Definition: Math.h:1840
vtkm::ATan
VTKM_EXEC_CONT vtkm::Float32 ATan(vtkm::Float32 x)
Compute the arc tangent of x.
Definition: Math.h:505
vtkm::TypeTraitsUnknownTag
Tag used to identify types that aren't Real, Integer, Scalar or Vector.
Definition: TypeTraits.h:20
vtkm::TypeTraitsScalarTag
Tag used to identify 0 dimensional types (scalars).
Definition: TypeTraits.h:44
vtkm::TypeTraitsVectorTag
Tag used to identify 1 dimensional types (vectors).
Definition: TypeTraits.h:51
vtkm::Vec< T, 3 >
Definition: Types.h:975
vtkm::Vec
A short fixed-length array.
Definition: Types.h:767
vtkm::UInt32
uint32_t UInt32
Definition: Types.h:161
vtkm::Float32
float Float32
Definition: Types.h:154
vtkm::VecTraits::ComponentType
typename VecType::ComponentType ComponentType
Type of the components in the vector.
Definition: VecTraits.h:73
vtkm::Int32
int32_t Int32
Definition: Types.h:160
vtkm::Float64
double Float64
Definition: Types.h:155
VTKM_CUDA_MATH_FUNCTION_32
#define VTKM_CUDA_MATH_FUNCTION_32(func)
Definition: Math.h:42
VTKM_EPSILON_64
#define VTKM_EPSILON_64
Definition: Math.h:1851
vtkm::ATanH
VTKM_EXEC_CONT vtkm::Float32 ATanH(vtkm::Float32 x)
Compute the hyperbolic arc tangent of x.
Definition: Math.h:879
vtkm::TanH
VTKM_EXEC_CONT vtkm::Float32 TanH(vtkm::Float32 x)
Compute the hyperbolic tangent of x.
Definition: Math.h:702
vtkm::VecTraits< T >
vtkm::Log
VTKM_EXEC_CONT vtkm::Float32 Log(vtkm::Float32 x)
Computes the natural logarithm of x.
Definition: Math.h:1455
vtkm::CountSetBits
VTKM_EXEC_CONT vtkm::Int32 CountSetBits(vtkm::UInt32 word)
Count the total number of bits set in word.
Definition: Math.h:2887
VTKM_NEG_INF_BITS_32
#define VTKM_NEG_INF_BITS_32
Definition: Math.h:1841
vtkm::ACos
VTKM_EXEC_CONT vtkm::Float32 ACos(vtkm::Float32 x)
Compute the arc cosine of x.
Definition: Math.h:446
Windows.h
vtkm::Exp2
VTKM_EXEC_CONT vtkm::Float32 Exp2(vtkm::Float32 x)
Computes 2**x, the base-2 exponential of x.
Definition: Math.h:1271
VecTraits.h
vtkm::Ldexp
VTKM_EXEC_CONT vtkm::Float32 Ldexp(vtkm::Float32 x, vtkm::Int32 exponent)
Definition: Math.h:2582