| 1 | /////////////////////////////////////////////////////////////// |
| 2 | // Copyright 2019 John Maddock. Distributed under the Boost |
| 3 | // Software License, Version 1.0. (See accompanying file |
| 4 | // LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt |
| 5 | // |
| 6 | // We used to use lexical_cast internally for quick conversions from integers |
| 7 | // to strings, but that breaks if the global locale is something other than "C". |
| 8 | // See https://github.com/boostorg/multiprecision/issues/167. |
| 9 | // |
| 10 | #ifndef BOOST_MP_DETAIL_ITOS_HPP |
| 11 | #define BOOST_MP_DETAIL_ITOS_HPP |
| 12 | |
| 13 | namespace boost { namespace multiprecision { namespace detail { |
| 14 | |
| 15 | template <class Integer> |
| 16 | std::string itos(Integer val) |
| 17 | { |
| 18 | if (!val) return "0" ; |
| 19 | std::string result; |
| 20 | bool isneg = false; |
| 21 | if (val < 0) |
| 22 | { |
| 23 | val = -val; |
| 24 | isneg = true; |
| 25 | } |
| 26 | while (val) |
| 27 | { |
| 28 | result.insert(p: result.begin(), c: char('0' + (val % 10))); |
| 29 | val /= 10; |
| 30 | } |
| 31 | if (isneg) |
| 32 | result.insert(p: result.begin(), c: '-'); |
| 33 | return result; |
| 34 | } |
| 35 | |
| 36 | |
| 37 | }}} // namespace boost::multiprecision::detail |
| 38 | |
| 39 | #endif |
| 40 | |