Reference documentation for deal.II version 9.0.0
signaling_nan.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2005 - 2017 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_signaling_nan_h
17 #define dealii_signaling_nan_h
18 
19 #include <deal.II/base/config.h>
20 #include <deal.II/base/tensor.h>
22 #include <deal.II/base/derivative_form.h>
23 #include <deal.II/base/point.h>
24 
25 #include <limits>
26 
27 
28 DEAL_II_NAMESPACE_OPEN
29 
30 namespace numbers
31 {
32 
33  namespace internal
34  {
40  namespace SignalingNaN
41  {
49  template <typename T>
51 
52 
58  template <>
59  struct NaNInitializer<float>
60  {
61  static float invalid_element ()
62  {
63  return std::numeric_limits<float>::signaling_NaN();
64  }
65  };
66 
67 
73  template <>
74  struct NaNInitializer<double>
75  {
76  static double invalid_element ()
77  {
78  return std::numeric_limits<double>::signaling_NaN();
79  }
80  };
81 
82 
88  template <int dim, typename T>
89  struct NaNInitializer<Tensor<1,dim,T> >
90  {
91  static Tensor<1,dim,T> invalid_element ()
92  {
93  Tensor<1,dim,T> nan_tensor;
94 
95  for (unsigned int i=0; i<dim; ++i)
96  nan_tensor[i] = NaNInitializer<T>::invalid_element();
97 
98  return nan_tensor;
99  }
100  };
101 
102 
103 
109  template <int rank, int dim, typename T>
110  struct NaNInitializer<Tensor<rank,dim,T> >
111  {
112  static Tensor<rank,dim,T> invalid_element ()
113  {
114  Tensor<rank,dim,T> nan_tensor;
115 
116  // recursively initialize sub-tensors with invalid elements
117  for (unsigned int i=0; i<dim; ++i)
118  nan_tensor[i] = NaNInitializer<Tensor<rank-1,dim,T> >::invalid_element();
119 
120  return nan_tensor;
121  }
122  };
123 
124 
125 
131  template <int dim, typename T>
132  struct NaNInitializer<Point<dim,T> >
133  {
134  static Point<dim,T> invalid_element ()
135  {
136  Point<dim,T> nan_point;
137 
138  for (unsigned int i=0; i<dim; ++i)
139  nan_point[i] = NaNInitializer<T>::invalid_element();
140 
141  return nan_point;
142  }
143  };
144 
145 
146 
152  template <int rank, int dim, typename T>
153  struct NaNInitializer<SymmetricTensor<rank,dim,T> >
154  {
155  static SymmetricTensor<rank,dim,T> invalid_element ()
156  {
157  // initialize symmetric tensors via the unrolled list of elements
159  for (unsigned int i=0; i<SymmetricTensor<rank,dim,T>::n_independent_components; ++i)
160  initializers[i] = NaNInitializer<T>::invalid_element();
161 
162  return SymmetricTensor<rank,dim,T>(initializers);
163  }
164  };
165 
166 
167 
173  template <int order, int dim, int spacedim, typename T>
174  struct NaNInitializer<DerivativeForm<order,dim,spacedim,T> >
175  {
176  static DerivativeForm<order,dim,spacedim,T> invalid_element ()
177  {
179 
180  // recursively initialize sub-tensors with invalid elements
181  for (unsigned int i=0; i<spacedim; ++i)
182  form[i] = NaNInitializer<Tensor<order,dim,T> >::invalid_element();
183 
184  return form;
185  }
186  };
187  }
188  }
189 
190 
191 
192 
217  template <class T>
218  T
220  {
221  // dispatch to the classes in the internal namespace because there
222  // we can do partial specializations, which is not possible for
223  // template functions such as the current one
225  }
226 }
227 
228 
229 DEAL_II_NAMESPACE_CLOSE
230 
231 #endif
Definition: point.h:104
Definition: mpi.h:53
T signaling_nan()