Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:44:34

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 // See http://boostorg.github.com/compute for more information.
0009 //---------------------------------------------------------------------------//
0010 
0011 #ifndef BOOST_COMPUTE_DETAIL_LITERAL_HPP
0012 #define BOOST_COMPUTE_DETAIL_LITERAL_HPP
0013 
0014 #include <iomanip>
0015 #include <limits>
0016 #include <sstream>
0017 
0018 #include <boost/type_traits/is_same.hpp>
0019 
0020 #include <boost/compute/types/fundamental.hpp>
0021 
0022 namespace boost {
0023 namespace compute {
0024 namespace detail {
0025 
0026 template<class T>
0027 std::string make_literal(T x)
0028 {
0029     std::stringstream s;
0030     s << std::setprecision(
0031 #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS
0032             std::numeric_limits<T>::max_digits10
0033 #else
0034             // We don't have max_digits10, so add 3 other digits (this is what is required for
0035             // float, and is one more than required for double).
0036             3 + std::numeric_limits<T>::digits10
0037 #endif
0038             )
0039       << std::scientific
0040       << x;
0041 
0042     if(boost::is_same<T, float>::value || boost::is_same<T, float_>::value){
0043         s << "f";
0044     }
0045 
0046     return s.str();
0047 }
0048 
0049 } // end detail namespace
0050 } // end compute namespace
0051 } // end boost namespace
0052 
0053 #endif // BOOST_COMPUTE_DETAIL_LITERAL_HPP