Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
Math.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 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/* Math.h (C) 2000-2024 */
9/* */
10/* Fonctions mathématiques diverses. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_MATH_H
13#define ARCANE_UTILS_MATH_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18#include "arcane/utils/Convert.h"
19
20#include <cmath>
21#include <cstdlib>
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
31namespace Arcane::math
32{
33
34/*---------------------------------------------------------------------------*/
35/*---------------------------------------------------------------------------*/
39ARCCORE_HOST_DEVICE inline double
40log(double v)
41{
42#ifdef ARCANE_CHECK_MATH
43 if (v==0.0 || v<0.0)
44 arcaneMathError(v,"log");
45#endif
46 return std::log(v);
47}
48
52ARCCORE_HOST_DEVICE inline long double
53log(long double v)
54{
55#ifdef ARCANE_CHECK_MATH
56 if (v==0.0 || v<0.0)
57 arcaneMathError(v,"log");
58#endif
59 return std::log(v);
60}
61
62/*---------------------------------------------------------------------------*/
63/*---------------------------------------------------------------------------*/
67ARCCORE_HOST_DEVICE inline double
68log10(double v)
69{
70#ifdef ARCANE_CHECK_MATH
71 if (v==0.0 || v<0.0)
72 arcaneMathError(v,"log");
73#endif
74 return std::log10(v);
75}
76
80ARCCORE_HOST_DEVICE inline long double
81log10(long double v)
82{
83#ifdef ARCANE_CHECK_MATH
84 if (v==0.0 || v<0.0)
85 arcaneMathError(v,"log");
86#endif
87 return std::log10(v);
88}
89
90/*---------------------------------------------------------------------------*/
91/*---------------------------------------------------------------------------*/
95ARCCORE_HOST_DEVICE inline double
96floor(double v)
97{
98 return std::floor(v);
99}
100
104ARCCORE_HOST_DEVICE inline long double
105floor(long double v)
106{
107 return std::floor(v);
108}
109
110/*---------------------------------------------------------------------------*/
111/*---------------------------------------------------------------------------*/
115ARCCORE_HOST_DEVICE inline double
116exp(double v)
117{
118 return std::exp(v);
119}
123ARCCORE_HOST_DEVICE inline long double
124exp(long double v)
125{
126 return std::exp(v);
127}
128
129/*---------------------------------------------------------------------------*/
130/*---------------------------------------------------------------------------*/
134ARCCORE_HOST_DEVICE inline double
135sqrt(double v)
136{
137#ifdef ARCANE_CHECK_MATH
138 if (v<0.)
139 arcaneMathError(v,"sqrt");
140#endif
141 return std::sqrt(v);
142}
146ARCCORE_HOST_DEVICE inline long double
147sqrt(long double v)
148{
149#ifdef ARCANE_CHECK_MATH
150 if (v<0.)
151 arcaneMathError(v,"sqrt");
152#endif
153 return std::sqrt(v);
154}
155
156/*---------------------------------------------------------------------------*/
157/*---------------------------------------------------------------------------*/
165ARCCORE_HOST_DEVICE inline double
166pow(double x,double y)
167{
168#ifdef ARCANE_CHECK_MATH
169 // Arguments invalides si x est négatif et y non entier
170 if (x<0.0 && ::floor(y)!=y)
171 arcaneMathError(x,y,"pow");
172#endif
173 return std::pow(x,y);
174}
175/*---------------------------------------------------------------------------*/
176/*---------------------------------------------------------------------------*/
184ARCCORE_HOST_DEVICE inline long double
185pow(long double x,long double y)
186{
187#ifdef ARCANE_CHECK_MATH
188 // Arguments invalides si x est négatif et y non entier
189 if (x<0.0 && ::floorl(y)!=y)
190 arcaneMathError(x,y,"pow");
191#endif
192 return std::pow(x,y);
193}
201ARCCORE_HOST_DEVICE inline long double
202pow(double x,long double y)
203{
204#ifdef ARCANE_CHECK_MATH
205 // Arguments invalides si x est négatif et y non entier
206 if (x<0.0 && ::floorl(y)!=y)
207 arcaneMathError(x,y,"pow");
208#endif
209 return std::pow(x,y);
210}
218ARCCORE_HOST_DEVICE inline long double
219pow(long double x,double y)
220{
221#ifdef ARCANE_CHECK_MATH
222 // Arguments invalides si x est négatif et y non entier
223 if (x<0.0 && ::floor(y)!=y)
224 arcaneMathError(x,y,"pow");
225#endif
226 return std::pow(x,y);
227}
228
229/*---------------------------------------------------------------------------*/
230/*---------------------------------------------------------------------------*/
238template<class T> ARCCORE_HOST_DEVICE inline T
239min(const T& a,const T& b)
240{
241 return ( (a<b) ? a : b );
242}
247ARCCORE_HOST_DEVICE inline long double
248min(long double a,long double b)
249{
250 return ( (a<b) ? a : b );
251}
256ARCCORE_HOST_DEVICE inline long double
257min(double a,long double b)
258{
259 return ( (a<b) ? a : b );
260}
265ARCCORE_HOST_DEVICE inline long double
266min(long double a,double b)
267{
268 return ( (a<b) ? a : b );
269}
274ARCCORE_HOST_DEVICE inline double
275min(double a,double b)
276{
277 return ( (a<b) ? a : b );
278}
283ARCCORE_HOST_DEVICE inline float
284min(float a,float b)
285{
286 return ( (a<b) ? a : b );
287}
292ARCCORE_HOST_DEVICE inline int
293min(int a,int b)
294{
295 return ( (a<b) ? a : b );
296}
297
298/*---------------------------------------------------------------------------*/
299/*---------------------------------------------------------------------------*/
307template<class T> ARCCORE_HOST_DEVICE inline T
308max(const T& a,const T& b)
309{
310 return ( (a<b) ? b : a );
311}
316ARCCORE_HOST_DEVICE inline long double
317max(long double a,long double b)
318{
319 return ( (a<b) ? b : a );
320}
325ARCCORE_HOST_DEVICE inline long double
326max(double a,long double b)
327{
328 return ( (a<b) ? b : a );
329}
334ARCCORE_HOST_DEVICE inline long double
335max(long double a,double b)
336{
337 return ( (a<b) ? b : a );
338}
343ARCCORE_HOST_DEVICE inline unsigned long
344max(unsigned long a,unsigned long b)
345{
346 return ( (a<b) ? b : a );
347}
352ARCCORE_HOST_DEVICE inline double
353max(double a,double b)
354{
355 return ( (a<b) ? b : a );
356}
361ARCCORE_HOST_DEVICE inline float
362max(float a,float b)
363{
364 return ( (a<b) ? b : a );
365}
370ARCCORE_HOST_DEVICE inline Int16
371max(Int16 a,Int16 b)
372{
373 return ( (a<b) ? b : a );
374}
379ARCCORE_HOST_DEVICE inline Int32
380max(Int32 a,Int32 b)
381{
382 return ( (a<b) ? b : a );
383}
388ARCCORE_HOST_DEVICE inline Int64
389max(Int32 a,Int64 b)
390{
391 return ( (a<b) ? b : a );
392}
397ARCCORE_HOST_DEVICE inline Int64
398max(Int64 a,Int32 b)
399{
400 return ( (a<b) ? b : a );
401}
406ARCCORE_HOST_DEVICE inline Int64
407max(Int64 a,Int64 b)
408{
409 return ( (a<b) ? b : a );
410}
411
412/*---------------------------------------------------------------------------*/
413/*---------------------------------------------------------------------------*/
418ARCCORE_HOST_DEVICE inline long double
419abs(long double a)
420{
421 return std::abs(a);
422}
427ARCCORE_HOST_DEVICE inline double
428abs(double a)
429{
430 return std::abs(a);
431}
436ARCCORE_HOST_DEVICE inline float
437abs(float a)
438{
439 return std::abs(a);
440}
441
446ARCCORE_HOST_DEVICE inline short
447abs(short a)
448{
449 return (a>0) ? a : (short)(-a);
450}
451
456ARCCORE_HOST_DEVICE inline int
457abs(int a)
458{
459 return (a>0) ? a : (-a);
460}
461
466ARCCORE_HOST_DEVICE inline long
467abs(long a)
468{
469 return (a>0L) ? a : (-a);
470}
471
476ARCCORE_HOST_DEVICE inline long long
477abs(long long a)
478{
479 return (a>0LL) ? a : (-a);
480}
481
482/*---------------------------------------------------------------------------*/
483/*---------------------------------------------------------------------------*/
497extern ARCANE_UTILS_EXPORT double
498truncateDouble(double v,Integer nb_digit);
499
500/*---------------------------------------------------------------------------*/
501/*---------------------------------------------------------------------------*/
509extern ARCANE_UTILS_EXPORT void
511
512/*---------------------------------------------------------------------------*/
513/*---------------------------------------------------------------------------*/
514
515} // End namespace Arcane::math
516
517/*---------------------------------------------------------------------------*/
518/*---------------------------------------------------------------------------*/
519
520#ifdef ARCANE_REAL_USE_APFLOAT
521#include "arcane/utils/MathApfloat.h"
522#endif
523
524/*---------------------------------------------------------------------------*/
525/*---------------------------------------------------------------------------*/
526
527#endif
Déclarations des types utilisés dans Arcane.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
T max(const T &a, const T &b, const T &c)
Retourne le maximum de trois éléments.
Definition MathUtils.h:392
ARCCORE_HOST_DEVICE Real2 min(Real2 a, Real2 b)
Retourne le minimum de deux Real2.
Definition MathUtils.h:336
Espace de nom pour les fonctions mathématiques.
Definition MathUtils.h:41
ARCCORE_HOST_DEVICE double log10(double v)
Logarithme décimal de v.
Definition Math.h:68
ARCCORE_HOST_DEVICE double floor(double v)
Arondir v à l'entier immédiatement inférieur.
Definition Math.h:96
ARCCORE_HOST_DEVICE double exp(double v)
Exponentielle de v.
Definition Math.h:116
ARCCORE_HOST_DEVICE double log(double v)
Logarithme népérien de v.
Definition Math.h:40
double truncateDouble(double v, Integer nb_digit)
Tronque la précision du réel v à nb_digit chiffres significatifs.
Definition Math.cc:78
ARCCORE_HOST_DEVICE double pow(double x, double y)
Fonction puissance.
Definition Math.h:166
ARCCORE_HOST_DEVICE double sqrt(double v)
Racine carrée de v.
Definition Math.h:135
ARCCORE_HOST_DEVICE void arcaneMathError(long double arg_value, const char *func_name)
Signale un argument invalide d'une fonction mathématique.