1 //---------------------------------------------------------------------------// 2 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com> 3 // 4 // Distributed under the Boost Software License, Version 1.0 5 // See accompanying file LICENSE_1_0.txt or copy at 6 // http://www.boost.org/LICENSE_1_0.txt 7 // 8 // See http://boostorg.github.com/compute for more information. 9 //---------------------------------------------------------------------------// 10 11 #ifndef BOOST_COMPUTE_DETAIL_LITERAL_HPP 12 #define BOOST_COMPUTE_DETAIL_LITERAL_HPP 13 14 #include <iomanip> 15 #include <limits> 16 #include <sstream> 17 18 #include <boost/type_traits/is_same.hpp> 19 20 #include <boost/compute/types/fundamental.hpp> 21 22 namespace boost { 23 namespace compute { 24 namespace detail { 25 26 template<class T> make_literal(T x)27std::string make_literal(T x) 28 { 29 std::stringstream s; 30 s << std::setprecision( 31 #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS 32 std::numeric_limits<T>::max_digits10 33 #else 34 // We don't have max_digits10, so add 3 other digits (this is what is required for 35 // float, and is one more than required for double). 36 3 + std::numeric_limits<T>::digits10 37 #endif 38 ) 39 << std::scientific 40 << x; 41 42 if(boost::is_same<T, float>::value || boost::is_same<T, float_>::value){ 43 s << "f"; 44 } 45 46 return s.str(); 47 } 48 49 } // end detail namespace 50 } // end compute namespace 51 } // end boost namespace 52 53 #endif // BOOST_COMPUTE_DETAIL_LITERAL_HPP 54