// @HEADER // ***************************************************************************** // Teuchos: Common Tools Package // // Copyright 2004 NTESS and the Teuchos contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #ifndef _TEUCHOS_SCALARTRAITS_DECL_HPP_ #define _TEUCHOS_SCALARTRAITS_DECL_HPP_ /*! \file Teuchos_ScalarTraitsDecl.hpp \brief Declaration and default implementation for basic traits for the scalar field type. */ #include "Teuchos_ConfigDefs.hpp" namespace Teuchos { template struct UndefinedScalarTraits { //! This function should not compile if there is an attempt to instantiate! static inline T notDefined() { return T::this_type_is_missing_a_specialization(); } }; /* This is the default structure used by ScalarTraits to produce a compile time error when the specialization does not exist for type T. */ /*! \brief This structure defines some basic traits for a scalar field type. * * Scalar traits are an essential part of templated codes. This structure offers * the basic traits of the templated scalar type, like defining zero and one, * and basic functions on the templated scalar type, like performing a square root. * * The functions in the templated base unspecialized struct are designed not to * compile (giving a nice compile-time error message) and therefore specializations * must be written for Scalar types actually used. * * \note
    * *
  1. The default defined specializations are provided for \c int, \c float, and \c double. * *
  2. If Teuchos is configured with Teuchos_ENABLE_COMPLEX=ON then * ScalarTraits also has a partial specialization for all * std::complex numbers of the form std::complex. * *
*/ template struct ScalarTraits { //! Mandatory typedef for result of magnitude typedef T magnitudeType; //! Typedef for half precision typedef T halfPrecision; //! Typedef for double precision typedef T doublePrecision; //! Typedef for coordinates typedef T coordinateType; //! Determines if scalar type is std::complex static const bool isComplex = false; //! Determines if scalar type is an ordinal type static const bool isOrdinal = false; //! Determines if scalar type supports relational operators such as <, >, <=, >=. static const bool isComparable = false; /** \brief Determines if scalar type have machine-specific parameters * (i.e. eps(), sfmin(), base(), prec(), t(), rnd(), emin(), rmin(), emax(), * rmax() are supported). */ static const bool hasMachineParameters = false; //! Returns relative machine precision. static inline magnitudeType eps() { return UndefinedScalarTraits::notDefined(); } //! Returns safe minimum (sfmin), such that 1/sfmin does not overflow. static inline magnitudeType sfmin() { return UndefinedScalarTraits::notDefined(); } //! Returns the base of the machine. static inline magnitudeType base() { return UndefinedScalarTraits::notDefined(); } //! Returns \c eps*base. static inline magnitudeType prec() { return UndefinedScalarTraits::notDefined(); } //! Returns the number of (base) digits in the mantissa. static inline magnitudeType t() { return UndefinedScalarTraits::notDefined(); } //! Returns 1.0 when rounding occurs in addition, 0.0 otherwise static inline magnitudeType rnd() { return UndefinedScalarTraits::notDefined(); } //! Returns the minimum exponent before (gradual) underflow. static inline magnitudeType emin() { return UndefinedScalarTraits::notDefined(); } //! Returns the underflow threshold - \c base^(emin-1) static inline magnitudeType rmin() { return UndefinedScalarTraits::notDefined(); } //! Returns the largest exponent before overflow. static inline magnitudeType emax() { return UndefinedScalarTraits::notDefined(); } //! Overflow theshold - \c (base^emax)*(1-eps) static inline magnitudeType rmax() { return UndefinedScalarTraits::notDefined(); } //! Returns the magnitudeType of the scalar type \c a. static inline magnitudeType magnitude(T a) { return UndefinedScalarTraits::notDefined(); } //! Returns representation of zero for this scalar type. static inline T zero() { return UndefinedScalarTraits::notDefined(); } //! Returns representation of one for this scalar type. static inline T one() { return UndefinedScalarTraits::notDefined(); } //! Returns the real part of the scalar type \c a. static inline magnitudeType real(T a) { return UndefinedScalarTraits::notDefined(); } //! Returns the imaginary part of the scalar type \c a. static inline magnitudeType imag(T a) { return UndefinedScalarTraits::notDefined(); } //! Returns the conjugate of the scalar type \c a. static inline T conjugate(T a) { return UndefinedScalarTraits::notDefined(); } //! Returns a number that represents NaN. static inline T nan() { return UndefinedScalarTraits::notDefined(); } //! Returns true if x is NaN or Inf. static inline bool isnaninf(const T& x) { return UndefinedScalarTraits::notDefined(); } //! Seed the random number generator returned by random(). static inline void seedrandom(unsigned int s) { int i; T t = &i; } //! Returns a random number (between -one() and +one()) of this scalar type. static inline T random() { return UndefinedScalarTraits::notDefined(); } //! Returns the name of this scalar type. static inline std::string name() { (void)UndefinedScalarTraits::notDefined(); return 0; } //! Returns a number of magnitudeType that is the square root of this scalar type \c x. static inline T squareroot(T x) { return UndefinedScalarTraits::notDefined(); } //! Returns the result of raising one scalar \c x to the power \c y. static inline T pow(T x, T y) { return UndefinedScalarTraits::notDefined(); } //! Returns the value of PI. static inline T pi() { return UndefinedScalarTraits::notDefined();} }; } // Teuchos namespace #endif // _TEUCHOS_SCALARTRAITS_DECL_HPP_