Reference documentation for deal.II version 8.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
numbers.h
1 // ---------------------------------------------------------------------
2 // @f$Id: numbers.h 30036 2013-07-18 16:55:32Z maier @f$
3 //
4 // Copyright (C) 2006 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__numbers_h
18 #define __deal2__numbers_h
19 
20 
21 #include <deal.II/base/config.h>
22 #include <deal.II/base/types.h>
23 #include <complex>
24 
26 
42 namespace numbers
43 {
47  static const double E = 2.7182818284590452354;
48 
52  static const double LOG2E = 1.4426950408889634074;
53 
57  static const double LOG10E = 0.43429448190325182765;
58 
62  static const double LN2 = 0.69314718055994530942;
63 
67  static const double LN10 = 2.30258509299404568402;
68 
72  static const double PI = 3.14159265358979323846;
73 
77  static const double PI_2 = 1.57079632679489661923;
78 
82  static const double PI_4 = 0.78539816339744830962;
83 
87  static const double SQRT2 = 1.41421356237309504880;
88 
92  static const double SQRT1_2 = 0.70710678118654752440;
93 
113  bool is_finite (const double x);
114 
120  bool is_finite (const std::complex<double> &x);
121 
127  bool is_finite (const std::complex<float> &x);
128 
141  bool is_finite (const std::complex<long double> &x);
142 
160  template <typename number>
162  {
171  static const bool is_complex = false;
172 
183  typedef number real_type;
184 
193  static
194  const number &conjugate (const number &x);
195 
204  static
205  real_type abs_square (const number &x);
206 
211  static
212  real_type abs (const number &x);
213  };
214 
215 
224  template <typename number>
225  struct NumberTraits<std::complex<number> >
226  {
236  static const bool is_complex = true;
237 
248  typedef number real_type;
249 
254  static
255  std::complex<number> conjugate (const std::complex<number> &x);
256 
266  static
267  real_type abs_square (const std::complex<number> &x);
268 
269 
274  static
275  real_type abs (const std::complex<number> &x);
276  };
277 
278 }
279 
280 
281 //TODO[WB]: eventually remove this namespace alias
282 /*
283  * Namespace alias with the old name for the numbers namespace. The namespace
284  * was originally called numbers, but has since been renamed to
285  * ::numbers when everything was moved into namespace dealii.
286  *
287  * @deprecated
288  */
289 namespace deal_II_numbers = numbers;
290 
291 
292 // --------------- inline and template functions ---------------- //
293 
294 namespace numbers
295 {
296  template <typename number>
297  const number &
299  {
300  return x;
301  }
302 
303 
304 
305  template <typename number>
308  {
309  return x * x;
310  }
311 
312 
313 
314  template <typename number>
316  NumberTraits<number>::abs (const number &x)
317  {
318  return std::fabs(x);
319  }
320 
321 
322 
323  template <typename number>
324  std::complex<number>
325  NumberTraits<std::complex<number> >::conjugate (const std::complex<number> &x)
326  {
327  return std::conj(x);
328  }
329 
330 
331 
332  template <typename number>
333  typename NumberTraits<std::complex<number> >::real_type
334  NumberTraits<std::complex<number> >::abs (const std::complex<number> &x)
335  {
336  return std::abs(x);
337  }
338 
339 
340 
341  template <typename number>
342  typename NumberTraits<std::complex<number> >::real_type
343  NumberTraits<std::complex<number> >::abs_square (const std::complex<number> &x)
344  {
345  return std::norm (x);
346  }
347 
348 }
349 
350 
351 
352 DEAL_II_NAMESPACE_CLOSE
353 
354 #endif
static const number & conjugate(const number &x)
Definition: numbers.h:298
static const double SQRT2
Definition: numbers.h:87
static const double PI_4
Definition: numbers.h:82
STL namespace.
static real_type abs(const number &x)
Definition: numbers.h:316
bool is_finite(const double x)
static const double PI
Definition: numbers.h:72
static const double LN2
Definition: numbers.h:62
static real_type abs_square(const number &x)
Definition: numbers.h:307
static const double E
Definition: numbers.h:47
static const bool is_complex
Definition: numbers.h:171
static const double PI_2
Definition: numbers.h:77
static const double LN10
Definition: numbers.h:67
static const double LOG2E
Definition: numbers.h:52
static const double SQRT1_2
Definition: numbers.h:92
static const double LOG10E
Definition: numbers.h:57