deal.II version GIT relicensing-6842-g793a97d2aa 2026-10-02 14:00:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
signaling_nan.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2015 - 2025 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_signaling_nan_h
14#define dealii_signaling_nan_h
15
16#include <deal.II/base/config.h>
17
19#include <deal.II/base/point.h>
21#include <deal.II/base/tensor.h>
22
23#include <limits>
24
25
27
28namespace numbers
29{
30 namespace internal
31 {
37 namespace SignalingNaN
38 {
46 template <typename T>
48
49
55 template <>
56 struct NaNInitializer<float>
57 {
58 static float
60 {
61 return std::numeric_limits<float>::signaling_NaN();
62 }
63 };
64
65
71 template <>
72 struct NaNInitializer<double>
73 {
74 static double
76 {
77 return std::numeric_limits<double>::signaling_NaN();
78 }
79 };
80
81
82 template <typename T, std::size_t width>
92
93
99 template <int dim, typename T>
100 struct NaNInitializer<Tensor<1, dim, T>>
101 {
102 static Tensor<1, dim, T>
104 {
105 Tensor<1, dim, T> nan_tensor;
106
107 for (unsigned int i = 0; i < dim; ++i)
108 nan_tensor[i] = NaNInitializer<T>::invalid_element();
109
110 return nan_tensor;
111 }
112 };
113
114
115
121 template <int rank, int dim, typename T>
122 struct NaNInitializer<Tensor<rank, dim, T>>
123 {
126 {
127 Tensor<rank, dim, T> nan_tensor;
128
129 // recursively initialize sub-tensors with invalid elements
130 for (unsigned int i = 0; i < dim; ++i)
131 nan_tensor[i] =
132 NaNInitializer<Tensor<rank - 1, dim, T>>::invalid_element();
133
134 return nan_tensor;
135 }
136 };
137
138
139
145 template <int dim, typename T>
146 struct NaNInitializer<Point<dim, T>>
147 {
148 static Point<dim, T>
150 {
151 Point<dim, T> nan_point;
152
153 for (unsigned int i = 0; i < dim; ++i)
154 nan_point[i] = NaNInitializer<T>::invalid_element();
155
156 return nan_point;
157 }
158 };
159
160
161
167 template <int rank, int dim, typename T>
168 struct NaNInitializer<SymmetricTensor<rank, dim, T>>
169 {
172 {
173 // initialize symmetric tensors via the unrolled list of elements
174 T initializers
176 for (unsigned int i = 0;
177 i < SymmetricTensor<rank, dim, T>::n_independent_components;
178 ++i)
179 initializers[i] = NaNInitializer<T>::invalid_element();
180
181 return SymmetricTensor<rank, dim, T>(initializers);
182 }
183 };
184
185
186
192 template <int order, int dim, int spacedim, typename T>
193 struct NaNInitializer<DerivativeForm<order, dim, spacedim, T>>
194 {
197 {
199
200 // recursively initialize sub-tensors with invalid elements
201 for (unsigned int i = 0; i < spacedim; ++i)
202 form[i] = NaNInitializer<Tensor<order, dim, T>>::invalid_element();
203
204 return form;
205 }
206 };
207 } // namespace SignalingNaN
208 } // namespace internal
209
210
211
266 template <class T>
267 T
269 {
270 // dispatch to the classes in the internal namespace because there
271 // we can do partial specializations, which is not possible for
272 // template functions such as the current one
274 }
275} // namespace numbers
276
277
279
280#endif
Definition point.h:111
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
T signaling_nan()