Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
MathApfloat.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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/* MathApfloat.h (C) 2000-2020 */
9/* */
10/* Various mathematical functions for the apfloat type. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_MATHAPFLOAT_H
13#define ARCANE_UTILS_MATHAPFLOAT_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include <apfloat.h>
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane::math
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28/*!
29 * \brief Natural logarithm of \a v.
30 */
31inline apfloat
32log(apfloat v)
33{
34#ifdef ARCANE_CHECK_MATH
35 if (v == 0.0 || v < 0.0)
37#endif
38 return ::log(v);
39}
40
41/*!
42 * \brief Round \a v down to the immediately lower integer.
43 */
44inline apfloat
45floor(apfloat v)
46{
47 return ::floor(v);
48}
49
50/*---------------------------------------------------------------------------*/
51/*---------------------------------------------------------------------------*/
52
53/*!
54 * \brief Exponential of \a v.
55 */
56inline apfloat
57exp(apfloat v)
58{
59 return ::exp(v);
60}
61
62/*---------------------------------------------------------------------------*/
63/*---------------------------------------------------------------------------*/
64
65/*!
66 * \brief Square root of \a v.
67 */
68inline apfloat
69sqrt(apfloat v)
70{
71#ifdef ARCANE_CHECK_MATH
72 if (v < 0.)
74#endif
75 return ::sqrt(v);
76}
77
78/*---------------------------------------------------------------------------*/
79/*---------------------------------------------------------------------------*/
80
81/*!
82 * \brief Power function.
83 *
84 * Calculates \a x raised to the power of \a y.
85 *
86 * \pre x>=0 or y is an integer
87 */
88inline apfloat
89pow(apfloat x, apfloat y)
90{
91#ifdef ARCANE_CHECK_MATH
92 // Arguments invalides si x est négatif et y non entier
93 if (x < 0.0 && ::floor(y) != y)
95#endif
96 return ::pow(x, y);
97}
98
99/*---------------------------------------------------------------------------*/
100/*---------------------------------------------------------------------------*/
101
102/*!
103 * \brief Returns the minimum of two real numbers.
104 * \ingroup GroupMathUtils
105 */
106inline apfloat
107min(apfloat a, apfloat b)
108{
109 return ((a < b) ? a : b);
110}
111
112/*---------------------------------------------------------------------------*/
113/*---------------------------------------------------------------------------*/
114
115/*!
116 * \brief Returns the maximum of two real numbers.
117 * \ingroup GroupMathUtils
118 */
119inline apfloat
120max(apfloat a, apfloat b)
121{
122 return ((a < b) ? b : a);
123}
124
125/*---------------------------------------------------------------------------*/
126/*---------------------------------------------------------------------------*/
127
128/*!
129 * \brief Returns the absolute value of a real number.
130 * \ingroup GroupMathUtils
131 */
132inline apfloat
133abs(apfloat a)
134{
135 return ::abs(a);
136}
137
138/*---------------------------------------------------------------------------*/
139/*---------------------------------------------------------------------------*/
140
141} // End namespace Arcane::math
142
143/*---------------------------------------------------------------------------*/
144/*---------------------------------------------------------------------------*/
145
146#endif
__host__ __device__ Real2 min(Real2 a, Real2 b)
Returns the minimum of two Real2.
Definition MathUtils.h:346
T max(const T &a, const T &b, const T &c)
Returns the maximum of three elements.
Definition MathUtils.h:407
double toDouble(Real r)
Converts a Real to double.
Namespace for mathematical functions.
Definition MathUtils.h:36
__host__ __device__ double pow(double x, double y)
Power function.
Definition Math.h:175
__host__ __device__ double floor(double v)
Round v down to the immediately lower integer.
Definition Math.h:100
__host__ __device__ double sqrt(double v)
Square root of v.
Definition Math.h:142
__host__ __device__ double log(double v)
Natural logarithm of v.
Definition Math.h:42
__host__ __device__ double exp(double v)
Exponential of v.
Definition Math.h:121
__host__ __device__ void arcaneMathError(long double arg_value, const char *func_name)
Signals an invalid argument in a mathematical function.