Teuchos - Trilinos Tools Package Version of the Day
Teuchos_ScalarTraits.cpp
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //                    Teuchos: Common Tools Package
00005 //                 Copyright (2004) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00025 //
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #include "Teuchos_ScalarTraits.hpp"
00030 #include "Teuchos_TestForException.hpp"
00031 
00032 // Define this to throw exceptions when any Teuchos::ScalarTraits function
00033 // encounters a NaN or an Inf.
00034 //#define TEUCHOS_SCALAR_TRAITS_THROW_NAN_INF_ERR
00035 
00036 
00037 namespace {
00038 
00039 // These functions exist to trick the compiler into not returning a warning
00040 // message for 0.0/0.0 or refusing to compile the code.  If a compiler gets
00041 // too smart, we can put these definitions into a different *.cpp file such
00042 // that most compilers would not be able to know at compile-time if a NaN or
00043 // an Inf was being created.
00044 
00045 float returnFloatZero() { return 0.0; }
00046 
00047 double returnDoubleZero() { return 0.0; }
00048 
00049 } // namespace
00050 
00051 
00052 void Teuchos::throwScalarTraitsNanInfError( const std::string &errMsg )
00053 {
00054 #ifdef TEUCHOS_SCALAR_TRAITS_THROW_NAN_INF_ERR
00055   TEST_FOR_EXCEPTION( true, std::runtime_error, errMsg );
00056 #endif
00057 }
00058 
00059 #ifdef HAVE_TEUCHOS_GNU_MP
00060 gmp_randclass Teuchos::gmp_rng ( gmp_randinit_default );
00061 #endif
00062 
00063 #ifdef HAVE_TEUCHOS_QD
00064 bool Teuchos::operator&&(const dd_real &a, const dd_real &b) {
00065   return !a.is_zero() && !b.is_zero();
00066 }
00067 bool Teuchos::operator&&(const qd_real &a, const qd_real &b) {
00068   return !a.is_zero() && !b.is_zero();
00069 }
00070 #endif
00071 
00072 #ifndef __sun
00073 // This is an intentional computation of NaN.
00074 const float  Teuchos::flt_nan = +returnFloatZero()/returnFloatZero();
00075 const double Teuchos::dbl_nan = +returnDoubleZero()/returnDoubleZero();
00076 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines