Teuchos - Trilinos Tools Package  Version of the Day
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  static const bool isComplex = false;
101  static const bool isOrdinal = false;
103  static const bool isComparable = false;
108  static const bool hasMachineParameters = false;
110  static inline magnitudeType eps() { return UndefinedScalarTraits<T>::notDefined(); }
112  static inline magnitudeType sfmin() { return UndefinedScalarTraits<T>::notDefined(); }
114  static inline magnitudeType base() { return UndefinedScalarTraits<T>::notDefined(); }
116  static inline magnitudeType prec() { return UndefinedScalarTraits<T>::notDefined(); }
118  static inline magnitudeType t() { return UndefinedScalarTraits<T>::notDefined(); }
120  static inline magnitudeType rnd() { return UndefinedScalarTraits<T>::notDefined(); }
122  static inline magnitudeType emin() { return UndefinedScalarTraits<T>::notDefined(); }
124  static inline magnitudeType rmin() { return UndefinedScalarTraits<T>::notDefined(); }
126  static inline magnitudeType emax() { return UndefinedScalarTraits<T>::notDefined(); }
128  static inline magnitudeType rmax() { return UndefinedScalarTraits<T>::notDefined(); }
130  static inline magnitudeType magnitude(T a) { return UndefinedScalarTraits<T>::notDefined(); }
132  static inline T zero() { return UndefinedScalarTraits<T>::notDefined(); }
134  static inline T one() { return UndefinedScalarTraits<T>::notDefined(); }
136  static inline magnitudeType real(T a) { return UndefinedScalarTraits<T>::notDefined(); }
138  static inline magnitudeType imag(T a) { return UndefinedScalarTraits<T>::notDefined(); }
140  static inline T conjugate(T a) { return UndefinedScalarTraits<T>::notDefined(); }
142  static inline T nan() { return UndefinedScalarTraits<T>::notDefined(); }
144  static inline bool isnaninf(const T& x) { return UndefinedScalarTraits<T>::notDefined(); }
146  static inline void seedrandom(unsigned int s) { int i; T t = &i; }
148  static inline T random() { return UndefinedScalarTraits<T>::notDefined(); }
150  static inline std::string name() { (void)UndefinedScalarTraits<T>::notDefined(); return 0; }
152  static inline T squareroot(T x) { return UndefinedScalarTraits<T>::notDefined(); }
154  static inline T pow(T x, T y) { return UndefinedScalarTraits<T>::notDefined(); }
156  static inline T pi() { return UndefinedScalarTraits<T>::notDefined();}
157 };
158 
159 
160 } // Teuchos namespace
161 
162 
163 #endif // _TEUCHOS_SCALARTRAITS_DECL_HPP_
Teuchos::ScalarTraits::sfmin
static magnitudeType sfmin()
Returns safe minimum (sfmin), such that 1/sfmin does not overflow.
Definition: Teuchos_ScalarTraitsDecl.hpp:112
Teuchos::ScalarTraits::rnd
static magnitudeType rnd()
Returns 1.0 when rounding occurs in addition, 0.0 otherwise.
Definition: Teuchos_ScalarTraitsDecl.hpp:120
Teuchos::ScalarTraits::magnitude
static magnitudeType magnitude(T a)
Returns the magnitudeType of the scalar type a.
Definition: Teuchos_ScalarTraitsDecl.hpp:130
Teuchos::ScalarTraits::nan
static T nan()
Returns a number that represents NaN.
Definition: Teuchos_ScalarTraitsDecl.hpp:142
Teuchos::ScalarTraits::zero
static T zero()
Returns representation of zero for this scalar type.
Definition: Teuchos_ScalarTraitsDecl.hpp:132
Teuchos::ScalarTraits::isnaninf
static bool isnaninf(const T &x)
Returns true if x is NaN or Inf.
Definition: Teuchos_ScalarTraitsDecl.hpp:144
Teuchos::ScalarTraits::seedrandom
static void seedrandom(unsigned int s)
Seed the random number generator returned by random().
Definition: Teuchos_ScalarTraitsDecl.hpp:146
Teuchos::ScalarTraits::real
static magnitudeType real(T a)
Returns the real part of the scalar type a.
Definition: Teuchos_ScalarTraitsDecl.hpp:136
Teuchos::ScalarTraits::pi
static T pi()
Returns the value of PI.
Definition: Teuchos_ScalarTraitsDecl.hpp:156
Teuchos::ScalarTraits::random
static T random()
Returns a random number (between -one() and +one()) of this scalar type.
Definition: Teuchos_ScalarTraitsDecl.hpp:148
Teuchos::ScalarTraits::hasMachineParameters
static const bool hasMachineParameters
Determines if scalar type have machine-specific parameters (i.e. eps(), sfmin(), base(),...
Definition: Teuchos_ScalarTraitsDecl.hpp:108
Teuchos::ScalarTraits::prec
static magnitudeType prec()
Returns eps*base.
Definition: Teuchos_ScalarTraitsDecl.hpp:116
Teuchos::ScalarTraits::t
static magnitudeType t()
Returns the number of (base) digits in the mantissa.
Definition: Teuchos_ScalarTraitsDecl.hpp:118
Teuchos::ScalarTraits::conjugate
static T conjugate(T a)
Returns the conjugate of the scalar type a.
Definition: Teuchos_ScalarTraitsDecl.hpp:140
Teuchos::ScalarTraits::pow
static T pow(T x, T y)
Returns the result of raising one scalar x to the power y.
Definition: Teuchos_ScalarTraitsDecl.hpp:154
Teuchos::ScalarTraits::isOrdinal
static const bool isOrdinal
Determines if scalar type is an ordinal type.
Definition: Teuchos_ScalarTraitsDecl.hpp:101
Teuchos::ScalarTraits::isComplex
static const bool isComplex
Determines if scalar type is std::complex.
Definition: Teuchos_ScalarTraitsDecl.hpp:99
Teuchos::ScalarTraits::emin
static magnitudeType emin()
Returns the minimum exponent before (gradual) underflow.
Definition: Teuchos_ScalarTraitsDecl.hpp:122
Teuchos::ScalarTraits::doublePrecision
T doublePrecision
Typedef for double precision.
Definition: Teuchos_ScalarTraitsDecl.hpp:97
Teuchos::ScalarTraits::one
static T one()
Returns representation of one for this scalar type.
Definition: Teuchos_ScalarTraitsDecl.hpp:134
Teuchos::ScalarTraits::isComparable
static const bool isComparable
Determines if scalar type supports relational operators such as <, >, <=, >=.
Definition: Teuchos_ScalarTraitsDecl.hpp:103
Teuchos::ScalarTraits
This structure defines some basic traits for a scalar field type.
Definition: Teuchos_ScalarTraitsDecl.hpp:90
Teuchos_ConfigDefs.hpp
Teuchos header file which uses auto-configuration information to include necessary C++ headers.
Teuchos::ScalarTraits::rmax
static magnitudeType rmax()
Overflow theshold - (base^emax)*(1-eps)
Definition: Teuchos_ScalarTraitsDecl.hpp:128
Teuchos::ScalarTraits::squareroot
static T squareroot(T x)
Returns a number of magnitudeType that is the square root of this scalar type x.
Definition: Teuchos_ScalarTraitsDecl.hpp:152
Teuchos::ScalarTraits::rmin
static magnitudeType rmin()
Returns the underflow threshold - base^(emin-1)
Definition: Teuchos_ScalarTraitsDecl.hpp:124
Teuchos::ScalarTraits::name
static std::string name()
Returns the name of this scalar type.
Definition: Teuchos_ScalarTraitsDecl.hpp:150
Teuchos::ScalarTraits::emax
static magnitudeType emax()
Returns the largest exponent before overflow.
Definition: Teuchos_ScalarTraitsDecl.hpp:126
Teuchos::ScalarTraits::magnitudeType
T magnitudeType
Mandatory typedef for result of magnitude.
Definition: Teuchos_ScalarTraitsDecl.hpp:93
Teuchos
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
Teuchos::ScalarTraits::halfPrecision
T halfPrecision
Typedef for half precision.
Definition: Teuchos_ScalarTraitsDecl.hpp:95
Teuchos::ScalarTraits::imag
static magnitudeType imag(T a)
Returns the imaginary part of the scalar type a.
Definition: Teuchos_ScalarTraitsDecl.hpp:138
Teuchos::ScalarTraits::eps
static magnitudeType eps()
Returns relative machine precision.
Definition: Teuchos_ScalarTraitsDecl.hpp:110
Teuchos::ScalarTraits::base
static magnitudeType base()
Returns the base of the machine.
Definition: Teuchos_ScalarTraitsDecl.hpp:114