Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
Limits.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/* Limits.h (C) 2000-2024 */
9/* */
10/* Files encapsulating <limits> and associated types. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_LIMITS_H
13#define ARCANE_UTILS_LIMITS_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/StdHeader.h"
18
19// Since <limits> defines min, max, abs, ... and some software
20// makes them macros, we remove them
21#ifdef min
22#undef min
23#endif
24#ifdef max
25#undef max
26#endif
27#ifdef abs
28#undef abs
29#endif
30#include <limits>
31
32#include <float.h>
33
34/*---------------------------------------------------------------------------*/
35/*---------------------------------------------------------------------------*/
36
37namespace Arcane
38{
39
40/*---------------------------------------------------------------------------*/
41/*---------------------------------------------------------------------------*/
42
43/*!
44 * \brief Information about the floating-point type.
45 * \note Mandatory specialization for floating-point types.
46 */
47template <typename T>
49{
50 public:
51
52 //! Indicates if the instantiation is for a floating-point type.
54};
55
56/*---------------------------------------------------------------------------*/
57/*---------------------------------------------------------------------------*/
58
59/*!
60 * \brief Specialization of the FloatInfo class for the \c float type.
61 */
62template <>
63class FloatInfo<float>
64{
65 public:
66
67 //! Indicates that the instantiation is for a floating-point type.
69
70 public:
71
72 ARCCORE_HOST_DEVICE static constexpr unsigned int precision() { return 1; }
73 ARCCORE_HOST_DEVICE static constexpr unsigned int maxDigit() { return FLT_DIG; }
74 ARCCORE_HOST_DEVICE static constexpr float epsilon() { return FLT_EPSILON; }
75 ARCCORE_HOST_DEVICE static constexpr float nearlyEpsilon() { return FLT_EPSILON * 10.0f; }
76 ARCCORE_HOST_DEVICE static constexpr float maxValue() { return FLT_MAX; }
77 ARCCORE_HOST_DEVICE static constexpr float zero() { return 0.0f; }
78};
79
80/*---------------------------------------------------------------------------*/
81/*---------------------------------------------------------------------------*/
82
83/*!
84 * \brief Specialization of the FloatInfo class for the <tt>double</tt> type.
85 */
86template <>
87class FloatInfo<double>
88{
89 public:
90
91 //! Indicates that the instantiation is for a floating-point type.
93
94 public:
95
96 ARCCORE_HOST_DEVICE static constexpr unsigned int precision() { return 2; }
97 ARCCORE_HOST_DEVICE static constexpr unsigned int maxDigit() { return DBL_DIG; }
98 ARCCORE_HOST_DEVICE static constexpr double epsilon() { return DBL_EPSILON; }
99 ARCCORE_HOST_DEVICE static constexpr double nearlyEpsilon() { return DBL_EPSILON * 10.0; }
100 ARCCORE_HOST_DEVICE static constexpr double maxValue() { return DBL_MAX; }
101 ARCCORE_HOST_DEVICE static constexpr double zero() { return 0.0; }
102};
103
104/*---------------------------------------------------------------------------*/
105/*---------------------------------------------------------------------------*/
106
107/*!
108 * \brief Specialization of the FloatInfo class for the type
109 * <tt>long double</tt>.
110 *
111 * \todo Verify that this class is valid for all architectures.
112 */
113template <>
114class FloatInfo<long double>
115{
116 public:
117
118 //! Indicates that the instantiation is for a floating-point type.
120
121 public:
122
123 ARCCORE_HOST_DEVICE static constexpr unsigned int precision() { return 3; }
124 ARCCORE_HOST_DEVICE static constexpr unsigned int maxDigit() { return LDBL_DIG; }
125 ARCCORE_HOST_DEVICE static constexpr long double epsilon() { return LDBL_EPSILON; }
126 ARCCORE_HOST_DEVICE static constexpr long double nearlyEpsilon() { return LDBL_EPSILON * 10.0; }
127 ARCCORE_HOST_DEVICE static constexpr long double maxValue() { return LDBL_MAX; }
128 ARCCORE_HOST_DEVICE static constexpr long double zero() { return 0.0l; }
129};
130
131#ifdef ARCANE_REAL_USE_APFLOAT
132/*---------------------------------------------------------------------------*/
133/*---------------------------------------------------------------------------*/
134
135/*!
136 * \brief Specialization of the FloatInfo class for the type
137 * <tt>long double</tt>.
138 *
139 * \todo Verify that this class is valid for all architectures.
140 */
141template <>
142class FloatInfo<apfloat>
143{
144 public:
145
146 //! Indicates that the instantiation is for a floating-point type.
147 typedef TrueType _IsFloatType;
148
149 public:
150
151 ARCCORE_HOST_DEVICE static constexpr unsigned int precision() { return 3; }
152 ARCCORE_HOST_DEVICE static constexpr unsigned int maxDigit() { return 35; }
153 ARCCORE_HOST_DEVICE static constexpr apfloat epsilon() { return 1e-30; }
154 ARCCORE_HOST_DEVICE static constexpr apfloat nearlyEpsilon() { return 1e-28; }
155 ARCCORE_HOST_DEVICE static constexpr apfloat maxValue() { return apfloat("1e1000"); }
156 ARCCORE_HOST_DEVICE static constexpr apfloat zero() { return apfloat("0.0"); }
157};
158#endif
159
160/*---------------------------------------------------------------------------*/
161/*---------------------------------------------------------------------------*/
162
163} // End namespace Arcane
164
165/*---------------------------------------------------------------------------*/
166/*---------------------------------------------------------------------------*/
167
168#endif
TrueType _IsFloatType
Indicates that the instantiation is for a floating-point type.
Definition Limits.h:92
TrueType _IsFloatType
Indicates that the instantiation is for a floating-point type.
Definition Limits.h:68
TrueType _IsFloatType
Indicates that the instantiation is for a floating-point type.
Definition Limits.h:119
Information about the floating-point type.
Definition Limits.h:49
FalseType _IsFloatType
Indicates if the instantiation is for a floating-point type.
Definition Limits.h:53
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --