OpenLB 1.7
Loading...
Searching...
No Matches
oalgorithm.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2020 Jan E. Marquardt
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#ifndef OLB_OALGORITHM_H
25#define OLB_OALGORITHM_H
26
27#include <algorithm>
28
29#include "core/meta.h"
30
31namespace olb {
32
33namespace util {
34
35// Max
36template< typename T >
37inline constexpr T max( T a, meta::id_t<T> b )
38{
39 return std::max(a, b);
40}
41template< typename T, class Compare >
42inline constexpr T max( T a, meta::id_t<T> b, Compare comp )
43{
44 return std::max(a, b, comp);
45}
46template< typename T >
47constexpr T inline max( std::initializer_list<T> ilist )
48{
49 return std::max(ilist);
50}
51template< typename T, class Compare >
52inline constexpr T max( std::initializer_list<T> ilist, Compare comp )
53{
54 return std::max(ilist, comp);
55}
56
57template <>
58inline float max<float>(float x, float y) any_platform
59{
60 return std::fmax(x, y);
61}
62
63template <>
64inline double max<double> (double x, double y) any_platform
65{
66 return std::fmax(x, y);
67}
68
69// Min
70template< typename T >
71inline constexpr T min( T a, meta::id_t<T> b )
72{
73 return std::min(a, b);
74}
75template< typename T, class Compare >
76inline constexpr T min( T a, meta::id_t<T> b, Compare comp )
77{
78 return std::min(a, b, comp);
79}
80template< typename T >
81inline constexpr T min( std::initializer_list<T> ilist )
82{
83 return std::min(ilist);
84}
85template< typename T, class Compare >
86inline constexpr T min( std::initializer_list<T> ilist, Compare comp )
87{
88 return std::min(ilist, comp);
89}
90
91template <>
92inline float min<float>(float x, float y) any_platform
93{
94 return std::fmin(x, y);
95}
96
97template <>
98inline double min<double>(double x, double y) any_platform
99{
100 return std::fmin(x, y);
101}
102
103
104} // namespace util
105
106} // namespace olb
107
108#endif
typename id< TYPE >::type id_t
Definition meta.h:92
cpu::simd::Pack< T > min(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
Definition pack.h:124
double min< double >(double x, double y) any_platform
Definition oalgorithm.h:98
float max< float >(float x, float y) any_platform
Definition oalgorithm.h:58
cpu::simd::Pack< T > max(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
Definition pack.h:130
float min< float >(float x, float y) any_platform
Definition oalgorithm.h:92
double max< double >(double x, double y) any_platform
Definition oalgorithm.h:64
Top level namespace for all of OpenLB.
#define any_platform
Define preprocessor macros for device-side functions, constant storage.
Definition platform.h:78