Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_ScalarTraitsDecl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef _TEUCHOS_SCALARTRAITS_DECL_HPP_
43 #define _TEUCHOS_SCALARTRAITS_DECL_HPP_
44 
49 #include "Teuchos_ConfigDefs.hpp"
50 
51 
52 namespace Teuchos {
53 
54 
55 template <typename T>
56 struct UndefinedScalarTraits
57 {
59  static inline T notDefined() { return T::this_type_is_missing_a_specialization(); }
60 };
61 
62 
63 /* This is the default structure used by ScalarTraits<T> to produce a compile time
64  error when the specialization does not exist for type <tt>T</tt>.
65 */
66 
67 
89 template <typename T>
91 {
93  typedef T magnitudeType;
95  typedef T halfPrecision;
97  typedef T doublePrecision;
99  typedef T coordinateType;
101  static const bool isComplex = false;
103  static const bool isOrdinal = false;
105  static const bool isComparable = false;
110  static const bool hasMachineParameters = false;
112  static inline magnitudeType eps() { return UndefinedScalarTraits<T>::notDefined(); }
114  static inline magnitudeType sfmin() { return UndefinedScalarTraits<T>::notDefined(); }
116  static inline magnitudeType base() { return UndefinedScalarTraits<T>::notDefined(); }
118  static inline magnitudeType prec() { return UndefinedScalarTraits<T>::notDefined(); }
120  static inline magnitudeType t() { return UndefinedScalarTraits<T>::notDefined(); }
122  static inline magnitudeType rnd() { return UndefinedScalarTraits<T>::notDefined(); }
124  static inline magnitudeType emin() { return UndefinedScalarTraits<T>::notDefined(); }
126  static inline magnitudeType rmin() { return UndefinedScalarTraits<T>::notDefined(); }
128  static inline magnitudeType emax() { return UndefinedScalarTraits<T>::notDefined(); }
130  static inline magnitudeType rmax() { return UndefinedScalarTraits<T>::notDefined(); }
132  static inline magnitudeType magnitude(T a) { return UndefinedScalarTraits<T>::notDefined(); }
134  static inline T zero() { return UndefinedScalarTraits<T>::notDefined(); }
136  static inline T one() { return UndefinedScalarTraits<T>::notDefined(); }
138  static inline magnitudeType real(T a) { return UndefinedScalarTraits<T>::notDefined(); }
140  static inline magnitudeType imag(T a) { return UndefinedScalarTraits<T>::notDefined(); }
142  static inline T conjugate(T a) { return UndefinedScalarTraits<T>::notDefined(); }
144  static inline T nan() { return UndefinedScalarTraits<T>::notDefined(); }
146  static inline bool isnaninf(const T& x) { return UndefinedScalarTraits<T>::notDefined(); }
148  static inline void seedrandom(unsigned int s) { int i; T t = &i; }
150  static inline T random() { return UndefinedScalarTraits<T>::notDefined(); }
152  static inline std::string name() { (void)UndefinedScalarTraits<T>::notDefined(); return 0; }
154  static inline T squareroot(T x) { return UndefinedScalarTraits<T>::notDefined(); }
156  static inline T pow(T x, T y) { return UndefinedScalarTraits<T>::notDefined(); }
158  static inline T pi() { return UndefinedScalarTraits<T>::notDefined();}
159 };
160 
161 
162 } // Teuchos namespace
163 
164 
165 #endif // _TEUCHOS_SCALARTRAITS_DECL_HPP_
T magnitudeType
Mandatory typedef for result of magnitude.
static magnitudeType eps()
Returns relative machine precision.
static T squareroot(T x)
Returns a number of magnitudeType that is the square root of this scalar type x.
static const bool isComparable
Determines if scalar type supports relational operators such as &lt;, &gt;, &lt;=, &gt;=.
static magnitudeType real(T a)
Returns the real part of the scalar type a.
Teuchos header file which uses auto-configuration information to include necessary C++ headers...
static T pow(T x, T y)
Returns the result of raising one scalar x to the power y.
static magnitudeType emax()
Returns the largest exponent before overflow.
static magnitudeType base()
Returns the base of the machine.
static const bool hasMachineParameters
Determines if scalar type have machine-specific parameters (i.e. eps(), sfmin(), base(), prec(), t(), rnd(), emin(), rmin(), emax(), rmax() are supported).
static std::string name()
Returns the name of this scalar type.
static magnitudeType rmax()
Overflow theshold - (base^emax)*(1-eps)
static magnitudeType sfmin()
Returns safe minimum (sfmin), such that 1/sfmin does not overflow.
This structure defines some basic traits for a scalar field type.
static T pi()
Returns the value of PI.
T coordinateType
Typedef for coordinates.
static T conjugate(T a)
Returns the conjugate of the scalar type a.
static const bool isOrdinal
Determines if scalar type is an ordinal type.
static magnitudeType prec()
Returns eps*base.
static magnitudeType t()
Returns the number of (base) digits in the mantissa.
static magnitudeType rmin()
Returns the underflow threshold - base^(emin-1)
T doublePrecision
Typedef for double precision.
static void seedrandom(unsigned int s)
Seed the random number generator returned by random().
static magnitudeType imag(T a)
Returns the imaginary part of the scalar type a.
static bool isnaninf(const T &x)
Returns true if x is NaN or Inf.
static magnitudeType magnitude(T a)
Returns the magnitudeType of the scalar type a.
static T nan()
Returns a number that represents NaN.
static T zero()
Returns representation of zero for this scalar type.
static T random()
Returns a random number (between -one() and +one()) of this scalar type.
T halfPrecision
Typedef for half precision.
static const bool isComplex
Determines if scalar type is std::complex.
static magnitudeType emin()
Returns the minimum exponent before (gradual) underflow.
static magnitudeType rnd()
Returns 1.0 when rounding occurs in addition, 0.0 otherwise.
static T one()
Returns representation of one for this scalar type.