Arcane  v3.16.0.0
Documentation développeur
Tout Classes Espaces de nommage Fichiers Fonctions Variables Définitions de type Énumérations Valeurs énumérées Amis Macros Groupes Pages Concepts
Numeric.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* Numeric.h (C) 2000-2020 */
9/* */
10/* Définitions des constantes numériques. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_DATATYPE_NUMERIC_H
13#define ARCANE_DATATYPE_NUMERIC_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Limits.h"
18#include "arcane/utils/Math.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23namespace Arcane
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
43template<class T>
45{
46 public:
52 constexpr ARCCORE_HOST_DEVICE static bool isNearlyZero (const T& a)
53 {
54 return (a==T());
55 }
56
62 constexpr ARCCORE_HOST_DEVICE static bool isZero (const T& a)
63 {
64 return (a==T());
65 }
66
72 constexpr ARCCORE_HOST_DEVICE static bool isNearlyEqual(const T& a,const T& b)
73 {
74 return (a==b);
75 }
76
82 constexpr ARCCORE_HOST_DEVICE static bool isNearlyEqualWithEpsilon(const T& a,const T& b,const T&)
83 {
84 return (a==b);
85 }
86
92 constexpr ARCCORE_HOST_DEVICE static bool isEqual(const T& a,const T& b)
93 {
94 return (a==b);
95 }
96};
97
98/*---------------------------------------------------------------------------*/
99/*---------------------------------------------------------------------------*/
107template<class T>
109{
110 private:
111 constexpr ARCCORE_HOST_DEVICE static T nepsilon() { return FloatInfo<T>::nearlyEpsilon(); }
112 public:
113 constexpr ARCCORE_HOST_DEVICE static bool isNearlyZero(T a)
114 {
115 return ( (a<0.) ? a>-nepsilon() : a<nepsilon() );
116 }
117
126 constexpr ARCCORE_HOST_DEVICE static bool isNearlyZeroWithEpsilon(T a,T epsilon)
127 {
128 return ( (a<0.) ? a>-epsilon : a<epsilon );
129 }
130
133 ARCCORE_HOST_DEVICE static bool isNearlyZero(T a,T b)
134 {
135 return ( (a<0.) ? a>-(b*nepsilon()) : a<(b*nepsilon()) );
136 }
137
138 constexpr ARCCORE_HOST_DEVICE static bool isTrueZero(T a) { return (a==FloatInfo<T>::zero()); }
139 constexpr ARCCORE_HOST_DEVICE static bool isZero(T a) { return (a==FloatInfo<T>::zero()); }
140 constexpr ARCCORE_HOST_DEVICE static bool isNearlyEqual(T a,T b)
141 {
142 T s = math::abs(a) + math::abs(b);
143 T d = a - b;
144 return (d==FloatInfo<T>::zero()) ? true : isNearlyZero(d/s);
145 }
146 constexpr ARCCORE_HOST_DEVICE static bool isNearlyEqualWithEpsilon(T a,T b,T epsilon)
147 {
148 T s = math::abs(a) + math::abs(b);
149 T d = a - b;
150 return (d==FloatInfo<T>::zero()) ? true : isNearlyZeroWithEpsilon(d/s,epsilon);
151 }
152 constexpr ARCCORE_HOST_DEVICE static bool isEqual(T a,T b)
153 {
154 return a==b;
155 }
156};
157
161template<>
162class TypeEqualT<float>
163: public FloatEqualT<float>
164{};
165
170template<>
171class TypeEqualT<double>
172: public FloatEqualT<double>
173{};
174
179template<>
180class TypeEqualT<long double>
181: public FloatEqualT<long double>
182{};
183
184#ifdef ARCANE_REAL_NOT_BUILTIN
189template<>
190class TypeEqualT<Real>
191: public FloatEqualT<Real>
192{};
193#endif
194
195/*---------------------------------------------------------------------------*/
196/*---------------------------------------------------------------------------*/
197
198namespace math
199{
200
211template<class _Type> constexpr ARCCORE_HOST_DEVICE inline bool
212isNearlyEqual(const _Type& a,const _Type& b)
213{
215}
216
218constexpr ARCCORE_HOST_DEVICE inline bool
223
234template<class _Type> constexpr ARCCORE_HOST_DEVICE inline bool
235isNearlyEqualWithEpsilon(const _Type& a,const _Type& b,const _Type& epsilon)
236{
238}
239
241ARCCORE_HOST_DEVICE constexpr inline bool
246
252template<class _Type> constexpr ARCCORE_HOST_DEVICE inline bool
253isEqual(const _Type& a,const _Type& b)
254{
255 return TypeEqualT<_Type>::isEqual(a,b);
256}
257
259ARCCORE_HOST_DEVICE constexpr inline bool
261{
262 return TypeEqualT<Real>::isEqual(a,b);
263}
264
275template<class _Type> constexpr ARCCORE_HOST_DEVICE inline bool
276isNearlyZeroWithEpsilon(const _Type& a,const _Type& epsilon)
277{
279}
280
288template<class _Type> constexpr ARCCORE_HOST_DEVICE inline bool
289isNearlyZero(const _Type& a)
290{
292}
293
299template<class _Type> constexpr ARCCORE_HOST_DEVICE inline bool
300isZero(const _Type& a)
301{
303}
304} // namespace math
305
306/*---------------------------------------------------------------------------*/
307/*---------------------------------------------------------------------------*/
308
309} // End namespace Arcane
310
311/*---------------------------------------------------------------------------*/
312/*---------------------------------------------------------------------------*/
313
314#endif
Définit l'opérateur == pour les flottants.
Definition Numeric.h:109
constexpr __host__ static __device__ bool isNearlyZeroWithEpsilon(T a, T epsilon)
Compare a à zéro à epsilon près.
Definition Numeric.h:126
__host__ static __device__ bool isNearlyZero(T a, T b)
Compare avec b*epsilon.
Definition Numeric.h:133
Informations sur le type flottant.
Definition Limits.h:48
Opérations de comparaisons pour un type numérique T.
Definition Numeric.h:45
constexpr __host__ static __device__ bool isNearlyZero(const T &a)
Compare a à zéro.
Definition Numeric.h:52
constexpr __host__ static __device__ bool isZero(const T &a)
Compare a à zéro.
Definition Numeric.h:62
constexpr __host__ static __device__ bool isEqual(const T &a, const T &b)
Compare a à b.
Definition Numeric.h:92
constexpr __host__ static __device__ bool isNearlyEqual(const T &a, const T &b)
Compare a à b.
Definition Numeric.h:72
constexpr __host__ static __device__ bool isNearlyEqualWithEpsilon(const T &a, const T &b, const T &)
Compare a à b.
Definition Numeric.h:82
constexpr __host__ __device__ bool isNearlyZeroWithEpsilon(const _Type &a, const _Type &epsilon)
Teste si une valeur est à peu près égale à zéro à un epsilon près.
Definition Numeric.h:276
constexpr __host__ __device__ bool isNearlyEqualWithEpsilon(const _Type &a, const _Type &b, const _Type &epsilon)
Teste si deux valeurs sont à un peu près égales. Pour les types entiers, cette fonction est équivalen...
Definition Numeric.h:235
constexpr __host__ __device__ bool isNearlyEqual(const _Type &a, const _Type &b)
Teste si deux valeurs sont à un peu près égales. Pour les types entiers, cette fonction est équivalen...
Definition Numeric.h:212
bool isZero(const BuiltInProxy< _Type > &a)
Teste si une valeur est exactement égale à zéro.
constexpr __host__ __device__ bool isEqual(const _Type &a, const _Type &b)
Teste l'égalité bit à bit entre deux valeurs.
Definition Numeric.h:253
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
double Real
Type représentant un réel.