OpenLB 1.7
Loading...
Searching...
No Matches
omath.h
Go to the documentation of this file.
1
2/* This file is part of the OpenLB library
3 *
4 * Copyright (C) 2024 Yuji Shimojima, 2020 Jan E. Marquardt
5 * E-mail contact: info@openlb.net
6 * The most recent release of OpenLB can be downloaded at
7 * <http://www.openlb.net/>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this program; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23*/
24
25#ifndef OLB_OMATH_H
26#define OLB_OMATH_H
27
28#include <cmath>
29#include <cstdlib>
30#include <iostream>
31#include <type_traits>
32
33namespace olb {
34
35namespace util {
36
37// Pow
38
39template <typename T, typename S>
40any_platform inline auto pow(T x, S y)
41 -> std::enable_if_t<std::is_floating_point_v<T> &&
42 std::is_floating_point_v<S>,
43 decltype(std::pow(x, y))>
44{
45#ifdef __CUDA_ARCH__
46 if constexpr (std::is_same_v<T, float> && std::is_same_v<S, float>) {
47 return ::powf(x, y);
48 }
49 else if constexpr (std::is_same_v<T, double> && std::is_same_v<S, double>) {
50 return ::pow(x, y);
51 }
52 else {
53 return ::pow(static_cast<double>(x), static_cast<double>(y));
54 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
55 }
56#else // __CUDA_ARCH__
57 return std::pow(x, y);
58#endif // __CUDA_ARCH__
59}
60
61template <typename T, typename S>
62any_platform inline auto pow(T x, S y)
63 -> std::enable_if_t<std::is_integral_v<S> && std::is_floating_point_v<T>,
64 decltype(std::pow(x, y))>
65{
66#ifdef __CUDA_ARCH__
67 if constexpr (std::is_same_v<T, float>) {
68 return ::powf(x, y);
69 }
70 else if constexpr (std::is_same_v<T, double>) {
71 return ::pow(x, y);
72 }
73 else {
74 return ::pow(static_cast<double>(x), y);
75 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
76 }
77#else //__CUDA_ARCH__
78 return std::pow(x, y);
79#endif //__CUDA_ARCH__
80}
81
82template <typename T, typename S>
83any_platform inline auto pow(T x, S y)
84 -> std::enable_if_t<std::is_integral_v<T> && std::is_floating_point_v<S>,
85 decltype(std::pow(x, y))>
86{
87#ifdef __CUDA_ARCH__
88 if constexpr (std::is_same_v<S, float>) {
89 return ::powf(x, y);
90 }
91 else if constexpr (std::is_same_v<S, double>) {
92 return ::pow(x, y);
93 }
94 else {
95 return ::pow(x, static_cast<double>(y));
96 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
97 }
98#else //__CUDA_ARCH__
99 return std::pow(x, y);
100#endif //__CUDA_ARCH__
101}
102template <typename T, typename S>
103any_platform inline std::enable_if_t<
104 std::is_integral_v<T> && std::is_integral_v<S>, double>
105pow(T x, S y)
106{
107#ifdef __CUDA_ARCH__
108 return ::pow(x, y);
109#else //__CUDA_ARCH__
110 return std::pow(x, y);
111#endif //__CUDA_ARCH__
112}
113
114any_platform inline float powf(float base, float exp)
115{
116#ifdef __CUDA_ARCH__
117 return ::powf(base, exp);
118#else //__CUDA_ARCH__
119 return std::pow(base, exp);
120#endif //__CUDA_ARCH__
121}
122
123any_platform inline float powf(int base, int exp)
124{
125#ifdef __CUDA_ARCH__
126 return ::powf(base, exp);
127#else //__CUDA_ARCH__
128 return std::pow(base, exp);
129#endif //__CUDA_ARCH__
130}
131
132inline long double powl(long double base, long double exp)
133{
134 return pow(base, exp);
135 //cuda dose not support this function.
136}
137
138//fmod
139template <typename T, typename S>
140any_platform inline auto fmod(T x, S y)
141 -> std::enable_if_t<std::is_floating_point_v<T> &&
142 std::is_floating_point_v<S>,
143 decltype(std::fmod(x, y))>
144{
145#ifdef __CUDA_ARCH__
146 if constexpr (std::is_same_v<T, float> && std::is_same_v<S, float>) {
147 return ::fmodf(x, y);
148 }
149 else if constexpr (std::is_same_v<T, double> && std::is_same_v<S, double>) {
150 return ::fmod(x, y);
151 }
152 else {
153 return ::fmod(static_cast<double>(x), static_cast<double>(y));
154 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
155 }
156#else //__CUDA_ARCH__
157 return std::fmod(x, y);
158#endif //__CUDA_ARCH__
159}
160
161template <typename T, typename S>
162any_platform inline std::enable_if_t<
163 std::is_integral_v<S> && std::is_floating_point_v<T>, T>
164fmod(T x, S y)
165{
166#ifdef __CUDA_ARCH__
167 if constexpr (std::is_same_v<T, float>) {
168 return ::fmodf(x, y);
169 }
170 else if constexpr (std::is_same_v<T, double>) {
171 return ::fmod(x, y);
172 }
173 else {
174 return ::fmod(static_cast<double>(x), y);
175 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
176 }
177#else //__CUDA_ARCH__
178 return std::fmod(x, y);
179#endif //__CUDA_ARCH__
180}
181
182template <typename T, typename S>
183any_platform inline std::enable_if_t<
184 std::is_integral_v<T> && std::is_floating_point_v<S>, S>
185fmod(T x, S y)
186{
187#ifdef __CUDA_ARCH__
188 if constexpr (std::is_same_v<S, float>) {
189 return ::fmodf(x, y);
190 }
191 else if constexpr (std::is_same_v<S, double>) {
192 return ::fmod(x, y);
193 }
194 else {
195 return ::fmod(x, static_cast<double>(y));
196 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
197 }
198#else //__CUDA_ARCH__
199 return std::fmod(x, y);
200#endif //__CUDA_ARCH__
201}
202
203any_platform inline float fmodf(float x, float y)
204{
205#ifdef __CUDA_ARCH__
206 return ::fmodf(x, y);
207#else //__CUDA_ARCH__
208 return std::fmod(x, y);
209#endif //__CUDA_ARCH__
210}
211
212any_platform inline float fmodf(int x, int y)
213{
214#ifdef __CUDA_ARCH__
215 return ::fmodf(x, y);
216#else //__CUDA_ARCH__
217 return std::fmod(x, y);
218#endif //__CUDA_ARCH__
219}
220
221inline long double fmodl(long double x, long double y)
222{
223 return fmod(x, y);
224 //cuda dose not support this function.
225}
226
227// Exp
228template <typename T>
229any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> exp(T x)
230{
231#ifdef __CUDA_ARCH__
232 if constexpr (std::is_same_v<T, float>) {
233 return ::expf(x);
234 }
235 else if constexpr (std::is_same_v<T, double>) {
236 return ::exp(x);
237 }
238 else {
239 return ::exp(static_cast<double>(x));
240 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
241 }
242#else //__CUDA_ARCH__
243 return std::exp(x);
244#endif //__CUDA_ARCH__
245}
246
247template <typename T>
248any_platform inline std::enable_if_t<std::is_integral_v<T>, double> exp(T arg)
249{
250#ifdef __CUDA_ARCH__
251 return ::exp(arg);
252#else //__CUDA_ARCH__
253 return std::exp(arg);
254#endif //__CUDA_ARCH__
255}
256
257any_platform inline float expf(float arg)
258{
259#ifdef __CUDA_ARCH__
260 return ::expf(arg);
261#else //__CUDA_ARCH__
262 return std::exp(arg);
263#endif //__CUDA_ARCH__
264}
265
266any_platform inline float expf(int arg)
267{
268#ifdef __CUDA_ARCH__
269 return ::expf(arg);
270#else //__CUDA_ARCH__
271 return std::exp(arg);
272#endif //__CUDA_ARCH__
273}
274
275inline long double expl(long double arg)
276{
277 return exp(arg);
278 //cuda dose not support this function.
279}
280
281template <typename T>
282any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> log(T x)
283{
284#ifdef __CUDA_ARCH__
285 if constexpr (std::is_same_v<T, float>) {
286 return ::logf(x);
287 }
288 else if constexpr (std::is_same_v<T, double>) {
289 return ::log(x);
290 }
291 else {
292 return ::log(static_cast<double>(x));
293 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
294 }
295#else //__CUDA_ARCH__
296 return std::log(x);
297#endif //__CUDA_ARCH__
298}
299
300template <typename T>
301any_platform inline std::enable_if_t<std::is_integral_v<T>, double> log(T arg)
302{
303#ifdef __CUDA_ARCH__
304 return ::log(arg);
305#else //__CUDA_ARCH__
306 return std::log(arg);
307#endif //__CUDA_ARCH__
308}
309
310any_platform inline float logf(float arg)
311{
312#ifdef __CUDA_ARCH__
313 return ::logf(arg);
314#else //__CUDA_ARCH__
315 return std::log(arg);
316#endif //__CUDA_ARCH__
317}
318
319any_platform inline float logf(int arg)
320{
321#ifdef __CUDA_ARCH__
322 return ::logf(arg);
323#else //__CUDA_ARCH__
324 return std::log(arg);
325#endif //__CUDA_ARCH__
326}
327
328inline long double logl(long double arg)
329{
330 return log(arg);
331 //cuda dose not support this function.
332}
333
334// Log10
335
336template <typename T>
337any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> log10(T x)
338{
339#ifdef __CUDA_ARCH__
340 if constexpr (std::is_same_v<T, float>) {
341 return ::log10f(x);
342 }
343 else if constexpr (std::is_same_v<T, double>) {
344 return ::log10(x);
345 }
346 else {
347 return ::log10(static_cast<double>(x));
348 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
349 }
350#else //__CUDA_ARCH__
351 return std::log10(x);
352#endif //__CUDA_ARCH__
353}
354
355template <typename T>
356any_platform inline std::enable_if_t<std::is_integral_v<T>, double> log10(T arg)
357{
358#ifdef __CUDA_ARCH__
359 return ::log10(arg);
360#else //__CUDA_ARCH__
361 return std::log10(arg);
362#endif //__CUDA_ARCH__
363}
364
365any_platform inline float log10f(float arg)
366{
367#ifdef __CUDA_ARCH__
368 return ::log10f(arg);
369#else //__CUDA_ARCH__
370 return std::log10(arg);
371#endif //__CUDA_ARCH__
372}
373
374any_platform inline float log10f(int arg)
375{
376#ifdef __CUDA_ARCH__
377 return ::log10f(arg);
378#else //__CUDA_ARCH__
379 return std::log10(arg);
380#endif //__CUDA_ARCH__
381}
382
383inline long double log10l(long double arg)
384{
385 return log10(arg);
386 //libcu++ of cuda dose not support long double. You will get warning in device code if you use.
387}
388
389// Log2
390
391template <typename T>
392any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> log2(T x)
393{
394#ifdef __CUDA_ARCH__
395 if constexpr (std::is_same_v<T, float>) {
396 return ::log2f(x);
397 }
398 else if constexpr (std::is_same_v<T, double>) {
399 return ::log2(x);
400 }
401 else {
402 return ::log2(static_cast<double>(x));
403 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
404 }
405#else //__CUDA_ARCH__
406 return std::log2(x);
407#endif //__CUDA_ARCH__
408}
409
410template <typename T>
411any_platform inline std::enable_if_t<std::is_integral_v<T>, double> log2(T arg)
412{
413#ifdef __CUDA_ARCH__
414 return ::log2(arg);
415#else //__CUDA_ARCH__
416 return std::log2(arg);
417#endif //__CUDA_ARCH__
418}
419
420any_platform inline float log2f(float arg)
421{
422#ifdef __CUDA_ARCH__
423 return ::log2f(arg);
424#else //__CUDA_ARCH__
425 return std::log2(arg);
426#endif //__CUDA_ARCH__
427}
428
429any_platform inline float log2f(int arg)
430{
431#ifdef __CUDA_ARCH__
432 return ::log2f(arg);
433#else //__CUDA_ARCH__
434 return std::log2(arg);
435#endif //__CUDA_ARCH__
436}
437
438inline long double log2l(long double arg)
439{
440 return log2(arg);
441 //libcu++ of cuda dose not support long double. You will get warning in device code if you use.
442}
443
444// Log1p
445template <typename T>
446any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> log1p(T x)
447{
448#ifdef __CUDA_ARCH__
449 if constexpr (std::is_same_v<T, float>) {
450 return ::log1pf(x);
451 }
452 else if constexpr (std::is_same_v<T, double>) {
453 return ::log1p(x);
454 }
455 else {
456 return ::log1p(static_cast<double>(x));
457 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
458 }
459#else //__CUDA_ARCH__
460 return std::log1p(x);
461#endif //__CUDA_ARCH__
462}
463
464template <typename T>
465any_platform inline std::enable_if_t<std::is_integral_v<T>, double> log1p(T arg)
466{
467#ifdef __CUDA_ARCH__
468 return ::log1p(arg);
469#else //__CUDA_ARCH__
470 return std::log1p(arg);
471#endif //__CUDA_ARCH__
472}
473
474any_platform inline float log1pf(float arg)
475{
476#ifdef __CUDA_ARCH__
477 return ::log1pf(arg);
478#else //__CUDA_ARCH__
479 return std::log1p(arg);
480#endif //__CUDA_ARCH__
481}
482
483any_platform inline float log1pf(int arg)
484{
485#ifdef __CUDA_ARCH__
486 return ::log1pf(arg);
487#else //__CUDA_ARCH__
488 return std::log1p(arg);
489#endif //__CUDA_ARCH__
490}
491
492inline long double log1pl(long double arg)
493{
494 return log1p(arg);
495 //libcu++ of cuda dose not support long double. You will get warning in device code if you use.
496}
497
498// Sqrt
499template <typename T>
500any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> sqrt(T x)
501{
502#ifdef __CUDA_ARCH__
503 if constexpr (std::is_same_v<T, float>) {
504 return ::sqrtf(x);
505 }
506 else if constexpr (std::is_same_v<T, double>) {
507 return ::sqrt(x);
508 }
509 else {
510 return ::sqrt(static_cast<double>(x));
511 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
512 }
513#else //__CUDA_ARCH__
514 return std::sqrt(x);
515#endif //__CUDA_ARCH__
516}
517
518template <typename T>
519any_platform inline std::enable_if_t<std::is_integral_v<T>, double> sqrt(T arg)
520{
521#ifdef __CUDA_ARCH__
522 return ::sqrt(arg);
523#else //__CUDA_ARCH__
524 return std::sqrt(arg);
525#endif //__CUDA_ARCH__
526}
527
528any_platform inline float sqrtf(float arg)
529{
530#ifdef __CUDA_ARCH__
531 return ::sqrtf(arg);
532#else //__CUDA_ARCH__
533 return std::sqrt(arg);
534#endif //__CUDA_ARCH__
535}
536
537any_platform inline float sqrtf(int arg)
538{
539#ifdef __CUDA_ARCH__
540 return ::sqrtf(arg);
541#else //__CUDA_ARCH__
542 return std::sqrt(arg);
543#endif //__CUDA_ARCH__
544}
545
546inline long double sqrtl(long double arg)
547{
548 return sqrt(arg);
549 //libcu++ of cuda dose not support long double. You will get warning in device code if you use.
550}
551
552// Sin
553
554any_platform inline float sinf(float x)
555{
556#ifdef __CUDA_ARCH__
557 return ::sinf(x);
558#else //__CUDA_ARCH__
559 return std::sin(x);
560#endif //__CUDA_ARCH__
561}
562
563any_platform inline float sinf(int x)
564{
565#ifdef __CUDA_ARCH__
566 return ::sinf(x);
567#else //__CUDA_ARCH__
568 return std::sin(x);
569#endif //__CUDA_ARCH__
570}
571
572template <typename T>
573any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> sin(T x)
574{
575#ifdef __CUDA_ARCH__
576 if constexpr (std::is_same_v<T, float>) {
577 return ::sinf(x);
578 }
579 else if constexpr (std::is_same_v<T, double>) {
580 return ::sin(x);
581 }
582 else {
583 return ::sin(static_cast<double>(x));
584 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
585 }
586#else //__CUDA_ARCH__
587 return std::sin(x);
588#endif //__CUDA_ARCH__
589}
590
591template <typename T>
592any_platform inline std::enable_if_t<std::is_integral_v<T>, double> sin(T x)
593{
594#ifdef __CUDA_ARCH__
595 return ::sin(x);
596#else //__CUDA_ARCH__
597 return std::sin(x);
598#endif //__CUDA_ARCH__
599}
600
601inline long double sinl(long double arg)
602{
603 return sin(arg);
604 //libcu++ of cuda dose not support long double. You will get warning in device code if you use.
605}
606
607// Sinh
608
609any_platform inline float sinhf(float x)
610{
611#ifdef __CUDA_ARCH__
612 return ::sinhf(x);
613#else //__CUDA_ARCH__
614 return std::sinh(x);
615#endif //__CUDA_ARCH__
616}
617
618any_platform inline float sinhf(int x)
619{
620#ifdef __CUDA_ARCH__
621 return ::sinhf(x);
622#else //__CUDA_ARCH__
623 return std::sinh(x);
624#endif //__CUDA_ARCH__
625}
626
627template <typename T>
628any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> sinh(T x)
629{
630#ifdef __CUDA_ARCH__
631 if constexpr (std::is_same_v<T, float>) {
632 return ::sinhf(x);
633 }
634 else if constexpr (std::is_same_v<T, double>) {
635 return ::sinh(x);
636 }
637 else {
638 return ::sinh(static_cast<double>(x));
639 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
640 }
641#else //__CUDA_ARCH__
642 return std::sinh(x);
643#endif //__CUDA_ARCH__
644}
645
646template <typename T>
647any_platform inline std::enable_if_t<std::is_integral_v<T>, double> sinh(T x)
648{
649#ifdef __CUDA_ARCH__
650 return ::sinh(x);
651#else //__CUDA_ARCH__
652 return std::sinh(x);
653#endif //__CUDA_ARCH__
654}
655
656inline long double sinhl(long double arg)
657{
658
659 return sinh(arg);
660 //libcu++ of cuda dose not support long double. You will get warning in device code if you use.
661}
662// Cos
663
664any_platform inline float cosf(float x)
665{
666#ifdef __CUDA_ARCH__
667 return ::cosf(x);
668#else //__CUDA_ARCH__
669 return std::cos(x);
670#endif //__CUDA_ARCH__
671}
672
673any_platform inline float cosf(int x)
674{
675#ifdef __CUDA_ARCH__
676 return ::cosf(x);
677#else //__CUDA_ARCH__
678 return std::cos(x);
679#endif //__CUDA_ARCH__
680}
681
682template <typename T>
683any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> cos(T x)
684{
685#ifdef __CUDA_ARCH__
686 if constexpr (std::is_same_v<T, float>) {
687 return ::cosf(x);
688 }
689 else if constexpr (std::is_same_v<T, double>) {
690 return ::cos(x);
691 }
692 else {
693 return ::cos(static_cast<double>(x));
694 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
695 }
696#else //__CUDA_ARCH__
697 return std::cos(x);
698#endif //__CUDA_ARCH__
699}
700
701template <typename T>
702any_platform inline std::enable_if_t<std::is_integral_v<T>, double> cos(T x)
703{
704#ifdef __CUDA_ARCH__
705 return ::cos(x);
706#else //__CUDA_ARCH__
707 return std::cos(x);
708#endif //__CUDA_ARCH__
709}
710
711inline long double cosl(long double arg)
712{
713 return cos(arg);
714 //libcu++ of cuda dose not support long double. You will get warning in device code if you use.
715}
716
717// Cosh
718
719any_platform inline float coshf(float x)
720{
721#ifdef __CUDA_ARCH__
722 return ::coshf(x);
723#else //__CUDA_ARCH__
724 return std::cosh(x);
725#endif //__CUDA_ARCH__
726}
727
728any_platform inline float coshf(int x)
729{
730#ifdef __CUDA_ARCH__
731 return ::coshf(x);
732#else //__CUDA_ARCH__
733 return std::cosh(x);
734#endif //__CUDA_ARCH__
735}
736
737template <typename T>
738any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> cosh(T x)
739{
740#ifdef __CUDA_ARCH__
741 if constexpr (std::is_same_v<T, float>) {
742 return ::coshf(x);
743 }
744 else if constexpr (std::is_same_v<T, double>) {
745 return ::cosh(x);
746 }
747 else {
748 return ::cosh(static_cast<double>(x));
749 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
750 }
751#else //__CUDA_ARCH__
752 return std::cosh(x);
753#endif //__CUDA_ARCH__
754}
755
756template <typename T>
757any_platform inline std::enable_if_t<std::is_integral_v<T>, double> cosh(T x)
758{
759#ifdef __CUDA_ARCH__
760 return ::cosh(x);
761#else //__CUDA_ARCH__
762 return std::cosh(x);
763#endif //__CUDA_ARCH__
764}
765
766inline long double coshl(long double arg)
767{
768 return cosh(arg);
769 //libcu++ of cuda dose not support long double. You will get warning in device code if you use.
770}
771
772// Tan
773any_platform inline float tanf(float x)
774{
775#ifdef __CUDA_ARCH__
776 return ::tanf(x);
777#else //__CUDA_ARCH__
778 return std::tan(x);
779#endif //__CUDA_ARCH__
780}
781
782any_platform inline float tanf(int x)
783{
784#ifdef __CUDA_ARCH__
785 return ::tanf(x);
786#else //__CUDA_ARCH__
787 return std::tan(x);
788#endif //__CUDA_ARCH__
789}
790
791template <typename T>
792any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> tan(T x)
793{
794#ifdef __CUDA_ARCH__
795 if constexpr (std::is_same_v<T, float>) {
796 return ::tanf(x);
797 }
798 else if constexpr (std::is_same_v<T, double>) {
799 return ::tan(x);
800 }
801 else {
802 return ::tan(static_cast<double>(x));
803 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
804 }
805#else //__CUDA_ARCH__
806 return std::tan(x);
807#endif //__CUDA_ARCH__
808}
809
810template <typename T>
811any_platform inline std::enable_if_t<std::is_integral_v<T>, double> tan(T x)
812{
813#ifdef __CUDA_ARCH__
814 return ::tan(x);
815#else //__CUDA_ARCH__
816 return std::tan(x);
817#endif //__CUDA_ARCH__
818}
819
820inline long double tanl(long double arg)
821{
822 return tan(arg);
823 //libcu++ of cuda dose not support long double. You will get warning in device code if you use.
824}
825
826// Tanh
827any_platform inline float tanhf(float x)
828{
829#ifdef __CUDA_ARCH__
830 return ::tanhf(x);
831#else //__CUDA_ARCH__
832 return std::tanh(x);
833#endif //__CUDA_ARCH__
834}
835
836any_platform inline float tanhf(int x)
837{
838#ifdef __CUDA_ARCH__
839 return ::tanhf(x);
840#else //__CUDA_ARCH__
841 return std::tanh(x);
842#endif //__CUDA_ARCH__
843}
844
845template <typename T>
846any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> tanh(T x)
847{
848#ifdef __CUDA_ARCH__
849 if constexpr (std::is_same_v<T, float>) {
850 return ::tanhf(x);
851 }
852 else if constexpr (std::is_same_v<T, double>) {
853 return ::tanh(x);
854 }
855 else {
856 return ::tanh(static_cast<double>(x));
857 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
858 }
859#else //__CUDA_ARCH__
860 return std::tanh(x);
861#endif //__CUDA_ARCH__
862}
863
864template <typename T>
865any_platform inline std::enable_if_t<std::is_integral_v<T>, double> tanh(T x)
866{
867#ifdef __CUDA_ARCH__
868 return ::tanh(x);
869#else //__CUDA_ARCH__
870 return std::tanh(x);
871#endif //__CUDA_ARCH__
872}
873
874inline long double tanhl(long double arg)
875{
876 return tanh(arg);
877 //libcu++ of cuda dose not support long double. You will get warning in device code if you use.
878}
879
880any_platform inline float asinf(float x)
881{
882#ifdef __CUDA_ARCH__
883 return ::asinf(x);
884#else //__CUDA_ARCH__
885 return std::asin(x);
886#endif //__CUDA_ARCH__
887}
888
889any_platform inline float asinf(int x)
890{
891#ifdef __CUDA_ARCH__
892 return ::asinf(x);
893#else //__CUDA_ARCH__
894 return std::asin(x);
895#endif //__CUDA_ARCH__
896}
897
898template <typename T>
899any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> asin(T x)
900{
901#ifdef __CUDA_ARCH__
902 if constexpr (std::is_same_v<T, float>) {
903 return ::asinf(x);
904 }
905 else if constexpr (std::is_same_v<T, double>) {
906 return ::asin(x);
907 }
908 else {
909 return ::asin(static_cast<double>(x));
910 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
911 }
912#else //__CUDA_ARCH__
913 return std::asin(x);
914#endif //__CUDA_ARCH__
915}
916
917template <typename T>
918any_platform inline std::enable_if_t<std::is_integral_v<T>, double> asin(T x)
919{
920#ifdef __CUDA_ARCH__
921 return ::asin(x);
922#else //__CUDA_ARCH__
923 return std::asin(x);
924#endif //__CUDA_ARCH__
925}
926
927inline long double asinl(long double arg)
928{
929 return asin(arg);
930 //cuda dose not support this function.
931}
932
933// Asinh
934any_platform inline float asinhf(float x)
935{
936#ifdef __CUDA_ARCH__
937 return ::asinhf(x);
938#else //__CUDA_ARCH__
939 return std::asinh(x);
940#endif //__CUDA_ARCH__
941}
942
943any_platform inline float asinhf(int x)
944{
945#ifdef __CUDA_ARCH__
946 return ::asinhf(x);
947#else //__CUDA_ARCH__
948 return std::asinh(x);
949#endif //__CUDA_ARCH__
950}
951
952template <typename T>
953any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> asinh(T x)
954{
955#ifdef __CUDA_ARCH__
956 if constexpr (std::is_same_v<T, float>) {
957 return ::asinhf(x);
958 }
959 else if constexpr (std::is_same_v<T, double>) {
960 return ::asinh(x);
961 }
962 else {
963 return ::asinh(static_cast<double>(x));
964 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
965 }
966#else //__CUDA_ARCH__
967 return std::asinh(x);
968#endif //__CUDA_ARCH__
969}
970
971template <typename T>
972any_platform inline std::enable_if_t<std::is_integral_v<T>, double> asinh(T x)
973{
974#ifdef __CUDA_ARCH__
975 return ::asinh(x);
976#else //__CUDA_ARCH__
977 return std::asinh(x);
978#endif //__CUDA_ARCH__
979}
980
981inline long double asinhl(long double arg)
982{
983 return std::asinhl(arg);
984 //cuda dose not support this function.
985}
986
987// Acos
988any_platform inline float acosf(float x)
989{
990#ifdef __CUDA_ARCH__
991 return ::acosf(x);
992#else //__CUDA_ARCH__
993 return std::acos(x);
994#endif //__CUDA_ARCH__
995}
996
997any_platform inline float acosf(int x)
998{
999#ifdef __CUDA_ARCH__
1000 return ::acosf(x);
1001#else //__CUDA_ARCH__
1002 return std::acos(x);
1003#endif //__CUDA_ARCH__
1004}
1005
1006template <typename T>
1007any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> acos(T x)
1008{
1009#ifdef __CUDA_ARCH__
1010 if constexpr (std::is_same_v<T, float>) {
1011 return ::acosf(x);
1012 }
1013 else if constexpr (std::is_same_v<T, double>) {
1014 return ::acos(x);
1015 }
1016 else {
1017 return ::acos(static_cast<double>(x));
1018 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
1019 }
1020#else //__CUDA_ARCH__
1021 return std::acos(x);
1022#endif //__CUDA_ARCH__
1023}
1024
1025template <typename T>
1026any_platform inline std::enable_if_t<std::is_integral_v<T>, double> acos(T x)
1027{
1028#ifdef __CUDA_ARCH__
1029 return ::acos(x);
1030#else //__CUDA_ARCH__
1031 return std::acos(x);
1032#endif //__CUDA_ARCH__
1033}
1034
1035inline long double acosl(long double arg)
1036{
1037 return acos(arg);
1038 //cuda dose not support this function.
1039}
1040
1041// Acosh
1042any_platform inline float acoshf(float x)
1043{
1044#ifdef __CUDA_ARCH__
1045 return ::acoshf(x);
1046#else //__CUDA_ARCH__
1047 return std::acosh(x);
1048#endif //__CUDA_ARCH__
1049}
1050
1051any_platform inline float acoshf(int x)
1052{
1053#ifdef __CUDA_ARCH__
1054 return ::acoshf(x);
1055#else //__CUDA_ARCH__
1056 return std::acosh(x);
1057#endif //__CUDA_ARCH__
1058}
1059
1060template <typename T>
1061any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> acosh(T x)
1062{
1063#ifdef __CUDA_ARCH__
1064 if constexpr (std::is_same_v<T, float>) {
1065 return ::acoshf(x);
1066 }
1067 else if constexpr (std::is_same_v<T, double>) {
1068 return ::acosh(x);
1069 }
1070 else {
1071 return ::acosh(static_cast<double>(x));
1072 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
1073 }
1074#else //__CUDA_ARCH__
1075 return std::acosh(x);
1076#endif //__CUDA_ARCH__
1077}
1078
1079template <typename T>
1080any_platform inline std::enable_if_t<std::is_integral_v<T>, double> acosh(T x)
1081{
1082#ifdef __CUDA_ARCH__
1083 return ::acosh(x);
1084#else //__CUDA_ARCH__
1085 return std::acosh(x);
1086#endif //__CUDA_ARCH__
1087}
1088
1089inline long double acoshl(long double arg)
1090{
1091 return std::acoshl(arg);
1092 //cuda dose not support this function.
1093}
1094
1095// Atan
1096any_platform inline float atanf(float x)
1097{
1098#ifdef __CUDA_ARCH__
1099 return ::atanf(x);
1100#else //__CUDA_ARCH__
1101 return std::atan(x);
1102#endif //__CUDA_ARCH__
1103}
1104
1105any_platform inline float atanf(int x)
1106{
1107#ifdef __CUDA_ARCH__
1108 return ::atanf(x);
1109#else //__CUDA_ARCH__
1110 return std::atan(x);
1111#endif //__CUDA_ARCH__
1112}
1113
1114template <typename T>
1115any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> atan(T x)
1116{
1117#ifdef __CUDA_ARCH__
1118 if constexpr (std::is_same_v<T, float>) {
1119 return ::atanf(x);
1120 }
1121 else if constexpr (std::is_same_v<T, double>) {
1122 return ::atan(x);
1123 }
1124 else {
1125 return ::atan(static_cast<double>(x));
1126 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
1127 }
1128#else //__CUDA_ARCH__
1129 return std::atan(x);
1130#endif //__CUDA_ARCH__
1131}
1132
1133template <typename T>
1134any_platform inline std::enable_if_t<std::is_integral_v<T>, double> atan(T x)
1135{
1136#ifdef __CUDA_ARCH__
1137 return ::atan(x);
1138#else //__CUDA_ARCH__
1139 return std::atan(x);
1140#endif //__CUDA_ARCH__
1141}
1142
1143inline long double atanl(long double arg)
1144{
1145 return atan(arg);
1146 //cuda dose not support this function.
1147}
1148
1149// Atan2
1150template <typename T, typename S>
1151any_platform inline auto atan2(T x, S y)
1152 -> std::enable_if_t<std::is_floating_point_v<T> &&
1153 std::is_floating_point_v<S>,
1154 decltype(std::atan2(x, y))>
1155{
1156#ifdef __CUDA_ARCH__
1157 if constexpr (std::is_same_v<T, float> && std::is_same_v<S, float>) {
1158 return ::atan2f(x, y);
1159 }
1160 else if constexpr (std::is_same_v<T, double> && std::is_same_v<S, double>) {
1161 return ::atan2(x, y);
1162 }
1163 else {
1164 return ::atan2(static_cast<double>(x), static_cast<double>(y));
1165 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
1166 }
1167#else // __CUDA_ARCH__
1168 return std::atan2(x, y);
1169#endif // __CUDA_ARCH__
1170}
1171
1172template <typename T, typename S>
1173any_platform inline std::enable_if_t<
1174 std::is_integral_v<S> && std::is_floating_point_v<T>, T>
1175atan2(T x, S y)
1176{
1177#ifdef __CUDA_ARCH__
1178 if constexpr (std::is_same_v<T, float>) {
1179 return ::atan2f(x, y);
1180 }
1181 else if constexpr (std::is_same_v<T, double>) {
1182 return ::atan2(x, y);
1183 }
1184 else {
1185 return ::atan2(static_cast<double>(x), y);
1186 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
1187 }
1188#else //__CUDA_ARCH__
1189 return std::atan2(x, y);
1190#endif //__CUDA_ARCH__
1191}
1192
1193template <typename T, typename S>
1194any_platform inline std::enable_if_t<
1195 std::is_integral_v<T> && std::is_floating_point_v<S>, S>
1196atan2(T x, S y)
1197{
1198#ifdef __CUDA_ARCH__
1199 if constexpr (std::is_same_v<S, float>) {
1200 return ::atan2f(x, y);
1201 }
1202 else if constexpr (std::is_same_v<S, double>) {
1203 return ::atan2(x, y);
1204 }
1205 else {
1206 return ::atan2(x, static_cast<double>(y));
1207 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
1208 }
1209#else //__CUDA_ARCH__
1210 return std::atan2(x, y);
1211#endif //__CUDA_ARCH__
1212}
1213template <typename T, typename S>
1214any_platform inline std::enable_if_t<
1215 std::is_integral_v<T> && std::is_integral_v<S>, double>
1216atan2(T x, S y)
1217{
1218#ifdef __CUDA_ARCH__
1219 return ::atan2(x, y);
1220#else //__CUDA_ARCH__
1221 return std::atan2(x, y);
1222#endif //__CUDA_ARCH__
1223}
1224
1225any_platform inline float atan2f(float base, float exp)
1226{
1227#ifdef __CUDA_ARCH__
1228 return ::atan2f(base, exp);
1229#else //__CUDA_ARCH__
1230 return std::atan2(base, exp);
1231#endif //__CUDA_ARCH__
1232}
1233
1234any_platform inline float atan2f(int base, int exp)
1235{
1236#ifdef __CUDA_ARCH__
1237 return ::atan2f(base, exp);
1238#else //__CUDA_ARCH__
1239 return std::atan2(base, exp);
1240#endif //__CUDA_ARCH__
1241}
1242
1243// Atanh
1244any_platform inline float atanhf(float x)
1245{
1246#ifdef __CUDA_ARCH__
1247 return ::atanhf(x);
1248#else //__CUDA_ARCH__
1249 return std::atanh(x);
1250#endif //__CUDA_ARCH__
1251}
1252
1253any_platform inline float atanhf(int x)
1254{
1255#ifdef __CUDA_ARCH__
1256 return ::atanhf(x);
1257#else //__CUDA_ARCH__
1258 return std::atanh(x);
1259#endif //__CUDA_ARCH__
1260}
1261
1262template <typename T>
1263any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> atanh(T x)
1264{
1265#ifdef __CUDA_ARCH__
1266 if constexpr (std::is_same_v<T, float>) {
1267 return ::atanhf(x);
1268 }
1269 else if constexpr (std::is_same_v<T, double>) {
1270 return ::atanh(x);
1271 }
1272 else {
1273 return ::atanh(static_cast<double>(x));
1274 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
1275 }
1276#else //__CUDA_ARCH__
1277 return std::atanh(x);
1278#endif //__CUDA_ARCH__
1279}
1280
1281template <typename T>
1282any_platform inline std::enable_if_t<std::is_integral_v<T>, double> atanh(T x)
1283{
1284#ifdef __CUDA_ARCH__
1285 return ::atanh(x);
1286#else //__CUDA_ARCH__
1287 return std::atanh(x);
1288#endif //__CUDA_ARCH__
1289}
1290
1291inline long double atanhl(long double arg)
1292{
1293 return atanh(arg);
1294 //cuda dose not support this function.
1295}
1296
1297// Rounding
1298// floor
1299any_platform inline float floorf(float x)
1300{
1301#ifdef __CUDA_ARCH__
1302 return ::floorf(x);
1303#else //__CUDA_ARCH__
1304 return std::floor(x);
1305#endif //__CUDA_ARCH__
1306}
1307
1308any_platform inline float floorf(int x)
1309{
1310#ifdef __CUDA_ARCH__
1311 return ::floorf(x);
1312#else //__CUDA_ARCH__
1313 return std::floor(x);
1314#endif //__CUDA_ARCH__
1315}
1316
1317template <typename T>
1318any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> floor(T x)
1319{
1320#ifdef __CUDA_ARCH__
1321 if constexpr (std::is_same_v<T, float>) {
1322 return ::floorf(x);
1323 }
1324 else if constexpr (std::is_same_v<T, double>) {
1325 return ::floor(x);
1326 }
1327 else {
1328 return ::floor(static_cast<double>(x));
1329 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
1330 }
1331#else //__CUDA_ARCH__
1332 return std::floor(x);
1333#endif //__CUDA_ARCH__
1334}
1335
1336template <typename T>
1337any_platform inline std::enable_if_t<std::is_integral_v<T>, double> floor(T x)
1338{
1339#ifdef __CUDA_ARCH__
1340 return ::floor(x);
1341#else //__CUDA_ARCH__
1342 return std::floor(x);
1343#endif //__CUDA_ARCH__
1344}
1345
1346inline long double floorl(long double arg)
1347{
1348 return floor(arg);
1349 //cuda dose not support this function.
1350}
1351
1352// ceil
1353any_platform inline float ceilf(float x)
1354{
1355#ifdef __CUDA_ARCH__
1356 return ::ceilf(x);
1357#else //__CUDA_ARCH__
1358 return std::ceil(x);
1359#endif //__CUDA_ARCH__
1360}
1361
1362any_platform inline float ceilf(int x)
1363{
1364#ifdef __CUDA_ARCH__
1365 return ::ceilf(x);
1366#else //__CUDA_ARCH__
1367 return std::ceil(x);
1368#endif //__CUDA_ARCH__
1369}
1370
1371template <typename T>
1372any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> ceil(T x)
1373{
1374#ifdef __CUDA_ARCH__
1375 if constexpr (std::is_same_v<T, float>) {
1376 return ::ceilf(x);
1377 }
1378 else if constexpr (std::is_same_v<T, double>) {
1379 return ::ceil(x);
1380 }
1381 else {
1382 return ::ceil(static_cast<double>(x));
1383 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
1384 }
1385#else //__CUDA_ARCH__
1386 return std::ceil(x);
1387#endif //__CUDA_ARCH__
1388}
1389
1390template <typename T>
1391any_platform inline std::enable_if_t<std::is_integral_v<T>, double> ceil(T x)
1392{
1393#ifdef __CUDA_ARCH__
1394 return ::ceil(x);
1395#else //__CUDA_ARCH__
1396 return std::ceil(x);
1397#endif //__CUDA_ARCH__
1398}
1399
1400inline long double ceill(long double arg)
1401{
1402 return ceil(arg);
1403 //cuda dose not support this function.
1404}
1405
1406// trunc
1407any_platform inline float truncf(float x)
1408{
1409#ifdef __CUDA_ARCH__
1410 return ::truncf(x);
1411#else //__CUDA_ARCH__
1412 return std::trunc(x);
1413#endif //__CUDA_ARCH__
1414}
1415
1416any_platform inline float truncf(int x)
1417{
1418#ifdef __CUDA_ARCH__
1419 return ::truncf(x);
1420#else //__CUDA_ARCH__
1421 return std::trunc(x);
1422#endif //__CUDA_ARCH__
1423}
1424
1425template <typename T>
1426any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> trunc(T x)
1427{
1428#ifdef __CUDA_ARCH__
1429 if constexpr (std::is_same_v<T, float>) {
1430 return ::truncf(x);
1431 }
1432 else if constexpr (std::is_same_v<T, double>) {
1433 return ::trunc(x);
1434 }
1435 else {
1436 return ::trunc(static_cast<double>(x));
1437 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
1438 }
1439#else //__CUDA_ARCH__
1440 return std::trunc(x);
1441#endif //__CUDA_ARCH__
1442}
1443
1444template <typename T>
1445any_platform inline std::enable_if_t<std::is_integral_v<T>, double> trunc(T x)
1446{
1447#ifdef __CUDA_ARCH__
1448 return ::trunc(x);
1449#else //__CUDA_ARCH__
1450 return std::trunc(x);
1451#endif //__CUDA_ARCH__
1452}
1453
1454inline long double truncl(long double arg)
1455{
1456 return std::truncl(arg);
1457 //cuda dose not support this function.
1458}
1459
1460// round
1461any_platform inline float roundf(float x)
1462{
1463#ifdef __CUDA_ARCH__
1464 return ::roundf(x);
1465#else //__CUDA_ARCH__
1466 return std::round(x);
1467#endif //__CUDA_ARCH__
1468}
1469
1470any_platform inline float roundf(int x)
1471{
1472#ifdef __CUDA_ARCH__
1473 return ::roundf(x);
1474#else //__CUDA_ARCH__
1475 return std::round(x);
1476#endif //__CUDA_ARCH__
1477}
1478
1479template <typename T>
1480any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> round(T x)
1481{
1482#ifdef __CUDA_ARCH__
1483 if constexpr (std::is_same_v<T, float>) {
1484 return ::roundf(x);
1485 }
1486 else if constexpr (std::is_same_v<T, double>) {
1487 return ::round(x);
1488 }
1489 else {
1490 return ::round(static_cast<double>(x));
1491 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
1492 }
1493#else //__CUDA_ARCH__
1494 return std::round(x);
1495#endif //__CUDA_ARCH__
1496}
1497
1498template <typename T>
1499any_platform inline std::enable_if_t<std::is_integral_v<T>, double> round(T x)
1500{
1501#ifdef __CUDA_ARCH__
1502 return ::round(x);
1503#else //__CUDA_ARCH__
1504 return std::round(x);
1505#endif //__CUDA_ARCH__
1506}
1507
1508inline long double roundl(long double arg)
1509{
1510 return std::roundl(arg);
1511 //cuda dose not support this function.
1512}
1513
1514template <typename T>
1515inline std::enable_if_t<std::is_arithmetic_v<T>, long> lround(T arg)
1516{
1517 return std::lround(arg);
1518}
1519
1520inline long lroundf(float arg) { return std::lroundf(arg); }
1521
1522inline long lroundl(long double arg) { return std::lroundl(arg); }
1523
1524template <typename T>
1525inline std::enable_if_t<std::is_arithmetic_v<T>, long long> llround(T arg)
1526{
1527 return std::llround(arg);
1528}
1529
1530inline long long llroundf(float arg) { return std::llroundf(arg); }
1531
1532inline long long llroundl(long double arg) { return std::llroundl(arg); }
1533
1534// Absolute
1535any_platform inline float fabsf(float x)
1536{
1537#ifdef __CUDA_ARCH__
1538 return ::fabsf(x);
1539#else //__CUDA_ARCH__
1540 return std::abs(x);
1541#endif //__CUDA_ARCH__
1542}
1543
1544any_platform inline float fabsf(int x)
1545{
1546#ifdef __CUDA_ARCH__
1547 return ::fabsf(x);
1548#else //__CUDA_ARCH__
1549 return std::abs(x);
1550#endif //__CUDA_ARCH__
1551}
1552
1553template <typename T>
1554any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> fabs(T x)
1555{
1556#ifdef __CUDA_ARCH__
1557 if constexpr (std::is_same_v<T, float>) {
1558 return ::fabsf(x);
1559 }
1560 else if constexpr (std::is_same_v<T, double>) {
1561 return ::fabs(x);
1562 }
1563 else {
1564 return ::fabs(static_cast<double>(x));
1565 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
1566 }
1567#else //__CUDA_ARCH__
1568 return std::fabs(x);
1569#endif //__CUDA_ARCH__
1570}
1571
1572template <typename T>
1573any_platform inline std::enable_if_t<std::is_integral_v<T>, double> fabs(T x)
1574{
1575#ifdef __CUDA_ARCH__
1576 return ::fabs(x);
1577#else //__CUDA_ARCH__
1578 return std::fabs(x);
1579#endif //__CUDA_ARCH__
1580}
1581
1582template <typename T>
1583any_platform inline std::enable_if_t<std::is_floating_point_v<T>, T> abs(T x)
1584{
1585#ifdef __CUDA_ARCH__
1586 if constexpr (std::is_same_v<T, float>) {
1587 return ::fabsf(x);
1588 }
1589 else if constexpr (std::is_same_v<T, double>) {
1590 return ::fabs(x);
1591 }
1592 else {
1593 return ::fabs(static_cast<double>(x));
1594 //libcu++ of cuda supports double and float. You will get warning in device code if you use in e.g. long double.
1595 }
1596#else //__CUDA_ARCH__
1597 return std::abs(x);
1598#endif //__CUDA_ARCH__
1599}
1600
1601template <typename T>
1602any_platform inline std::enable_if_t<std::is_integral_v<T>, T> abs(T x)
1603{
1604#ifdef __CUDA_ARCH__
1605 return ::abs(x);
1606#else //__CUDA_ARCH__
1607 return std::abs(x);
1608#endif //__CUDA_ARCH__
1609}
1610
1611inline long double fabs(long double arg) { return std::abs(arg); }
1612
1613template <std::integral T>
1615{
1616 return fabs(x) <= std::numeric_limits<T>::epsilon();
1617}
1618
1619//isnan
1620template <typename T>
1621any_platform inline bool isnan(T arg)
1622{
1623#ifdef __CUDA_ARCH__
1624 return ::isnan(arg);
1625#else
1626 return std::isnan(arg);
1627#endif
1628}
1629} // namespace util
1630
1631} // namespace olb
1632
1633#endif
long double atanl(long double arg)
Definition omath.h:1143
ADf< T, DIM > abs(const ADf< T, DIM > &a)
Definition aDiff.h:1019
ADf< T, DIM > ceil(const ADf< T, DIM > &a)
Definition aDiff.h:900
ADf< T, DIM > floor(const ADf< T, DIM > &a)
Definition aDiff.h:869
Expr sqrt(Expr x)
Definition expr.cpp:199
long double fmodl(long double x, long double y)
Definition omath.h:221
ADf< T, DIM > tan(const ADf< T, DIM > &a)
Definition aDiff.h:587
ADf< T, DIM > fmod(const ADf< T, DIM > &a, const ADf< T, DIM > &b)
Definition aDiff.h:703
any_platform float atan2f(float base, float exp)
Definition omath.h:1225
long double asinl(long double arg)
Definition omath.h:927
long double sinl(long double arg)
Definition omath.h:601
ADf< T, DIM > atan2(const T &y, const ADf< T, DIM > &x)
Definition aDiff.h:623
long double tanhl(long double arg)
Definition omath.h:874
ADf< float, DIM > llroundf(const ADf< float, DIM > &a)
Definition aDiff.h:984
ADf< T, DIM > asinh(const ADf< T, DIM > &a)
Definition aDiff.h:669
any_platform float asinf(float x)
Definition omath.h:880
ADf< long double, DIM > log1pl(const ADf< long double, DIM > &a)
Definition aDiff.h:550
any_platform float sinhf(float x)
Definition omath.h:609
ADf< T, DIM > lround(const ADf< T, DIM > &a)
Definition aDiff.h:957
any_platform std::enable_if_t< std::is_floating_point_v< T >, T > trunc(T x)
Definition omath.h:1426
long double truncl(long double arg)
Definition omath.h:1454
any_platform float sqrtf(float arg)
Definition omath.h:528
ADf< float, DIM > log10f(const ADf< float, DIM > &a)
Definition aDiff.h:505
ADf< T, DIM > log(const ADf< T, DIM > &a)
Definition aDiff.h:475
any_platform float acoshf(float x)
Definition omath.h:1042
ADf< long double, DIM > expl(const ADf< long double, DIM > &a)
Definition aDiff.h:469
ADf< float, DIM > logf(const ADf< float, DIM > &a)
Definition aDiff.h:484
ADf< long double, DIM > log2l(const ADf< long double, DIM > &a)
Definition aDiff.h:532
any_platform float tanhf(float x)
Definition omath.h:827
long double asinhl(long double arg)
Definition omath.h:981
any_platform float atanf(float x)
Definition omath.h:1096
any_platform bool isnan(T arg)
Definition omath.h:1621
long double tanl(long double arg)
Definition omath.h:820
long double sqrtl(long double arg)
Definition omath.h:546
ADf< float, DIM > roundf(const ADf< float, DIM > &a)
Definition aDiff.h:944
ADf< T, DIM > round(const ADf< T, DIM > &a)
Definition aDiff.h:928
any_platform bool closeToZero(T x)
Definition omath.h:1614
ADf< float, DIM > log2f(const ADf< float, DIM > &a)
Definition aDiff.h:526
ADf< long double, DIM > log10l(const ADf< long double, DIM > &a)
Definition aDiff.h:511
ADf< T, DIM > llround(const ADf< T, DIM > &a)
Definition aDiff.h:978
any_platform float truncf(float x)
Definition omath.h:1407
ADf< float, DIM > floorf(const ADf< float, DIM > &a)
Definition aDiff.h:888
ADf< T, DIM > sin(const ADf< T, DIM > &a)
Definition aDiff.h:569
ADf< float, DIM > expf(const ADf< float, DIM > &a)
Definition aDiff.h:463
ADf< T, DIM > acosh(const ADf< T, DIM > &a)
Definition aDiff.h:675
long double acosl(long double arg)
Definition omath.h:1035
ADf< long double, DIM > floorl(const ADf< long double, DIM > &a)
Definition aDiff.h:894
ADf< float, DIM > fabsf(const ADf< float, DIM > &a)
Definition aDiff.h:1007
long double powl(long double base, long double exp)
Definition omath.h:132
any_platform float fmodf(float x, float y)
Definition omath.h:203
Expr pow(Expr base, Expr exp)
Definition expr.cpp:207
any_platform float asinhf(float x)
Definition omath.h:934
long double acoshl(long double arg)
Definition omath.h:1089
ADf< T, DIM > asin(const ADf< T, DIM > &a)
Definition aDiff.h:596
ADf< T, DIM > log1p(const ADf< T, DIM > &a)
Definition aDiff.h:538
any_platform float cosf(float x)
Definition omath.h:664
any_platform float acosf(float x)
Definition omath.h:988
long double sinhl(long double arg)
Definition omath.h:656
any_platform float tanf(float x)
Definition omath.h:773
ADf< float, DIM > lroundf(const ADf< float, DIM > &a)
Definition aDiff.h:966
ADf< T, DIM > cosh(const ADf< T, DIM > &a)
Definition aDiff.h:657
ADf< T, DIM > sinh(const ADf< T, DIM > &a)
Definition aDiff.h:651
long double atanhl(long double arg)
Definition omath.h:1291
ADf< long double, DIM > lroundl(const ADf< long double, DIM > &a)
Definition aDiff.h:972
Expr fabs(Expr x)
Definition expr.cpp:203
ADf< long double, DIM > roundl(const ADf< long double, DIM > &a)
Definition aDiff.h:950
ADf< T, DIM > acos(const ADf< T, DIM > &a)
Definition aDiff.h:605
ADf< long double, DIM > llroundl(const ADf< long double, DIM > &a)
Definition aDiff.h:990
any_platform float powf(float base, float exp)
Definition omath.h:114
any_platform float atanhf(float x)
Definition omath.h:1244
long double cosl(long double arg)
Definition omath.h:711
any_platform float sinf(float x)
Definition omath.h:554
ADf< long double, DIM > ceill(const ADf< long double, DIM > &a)
Definition aDiff.h:922
ADf< T, DIM > tanh(const ADf< T, DIM > &a)
Definition aDiff.h:663
long double coshl(long double arg)
Definition omath.h:766
ADf< float, DIM > log1pf(const ADf< float, DIM > &a)
Definition aDiff.h:544
ADf< T, DIM > log10(const ADf< T, DIM > &a)
Definition aDiff.h:496
Expr exp(Expr x)
Definition expr.cpp:211
ADf< T, DIM > atan(const ADf< T, DIM > &a)
Definition aDiff.h:614
ADf< long double, DIM > logl(const ADf< long double, DIM > &a)
Definition aDiff.h:490
ADf< float, DIM > ceilf(const ADf< float, DIM > &a)
Definition aDiff.h:916
ADf< T, DIM > atanh(const ADf< T, DIM > &a)
Definition aDiff.h:689
any_platform float coshf(float x)
Definition omath.h:719
ADf< T, DIM > log2(const ADf< T, DIM > &a)
Definition aDiff.h:517
ADf< T, DIM > cos(const ADf< T, DIM > &a)
Definition aDiff.h:578
Top level namespace for all of OpenLB.
#define any_platform
Define preprocessor macros for device-side functions, constant storage.
Definition platform.h:77