MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / str

Method str

extern/boost/boost/multiprecision/cpp_dec_float.hpp:1894–2061  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1892
1893template <unsigned Digits10, class ExponentType, class Allocator>
1894std::string cpp_dec_float<Digits10, ExponentType, Allocator>::str(std::intmax_t number_of_digits, std::ios_base::fmtflags f) const
1895{
1896 if ((this->isinf)())
1897 {
1898 if (this->isneg())
1899 return "-inf";
1900 else if (f & std::ios_base::showpos)
1901 return "+inf";
1902 else
1903 return "inf";
1904 }
1905 else if ((this->isnan)())
1906 {
1907 return "nan";
1908 }
1909
1910 std::string str;
1911 std::intmax_t org_digits(number_of_digits);
1912 exponent_type my_exp = order();
1913
1914 if (!(f & std::ios_base::fixed) && (number_of_digits == 0))
1915 number_of_digits = cpp_dec_float_max_digits10;
1916
1917 if (f & std::ios_base::fixed)
1918 {
1919 number_of_digits += my_exp + 1;
1920 }
1921 else if (f & std::ios_base::scientific)
1922 ++number_of_digits;
1923 // Determine the number of elements needed to provide the requested digits from cpp_dec_float<Digits10, ExponentType, Allocator>.
1924 const std::size_t number_of_elements = (std::min)(static_cast<std::size_t>((number_of_digits / static_cast<std::size_t>(cpp_dec_float_elem_digits10)) + 2u),
1925 static_cast<std::size_t>(cpp_dec_float_elem_number));
1926
1927 // Extract the remaining digits from cpp_dec_float<Digits10, ExponentType, Allocator> after the decimal point.
1928 std::stringstream ss;
1929 ss.imbue(std::locale::classic());
1930 ss << data[0];
1931 // Extract all of the digits from cpp_dec_float<Digits10, ExponentType, Allocator>, beginning with the first data element.
1932 for (std::size_t i = static_cast<std::size_t>(1u); i < number_of_elements; i++)
1933 {
1934 ss << std::setw(static_cast<std::streamsize>(cpp_dec_float_elem_digits10))
1935 << std::setfill(static_cast<char>('0'))
1936 << data[i];
1937 }
1938 str += ss.str();
1939
1940 bool have_leading_zeros = false;
1941
1942 if (number_of_digits == 0)
1943 {
1944 // We only get here if the output format is "fixed" and we just need to
1945 // round the first non-zero digit.
1946 number_of_digits -= my_exp + 1; // reset to original value
1947 if (number_of_digits)
1948 {
1949 str.insert(static_cast<std::string::size_type>(0), std::string::size_type(number_of_digits), '0');
1950 have_leading_zeros = true;
1951 }

Callers 15

WhereMethod · 0.80
analyzeMethod · 0.80
stress_test.hFile · 0.80
FlushMethod · 0.80
Uint128ToFormattedStringFunction · 0.80
rational.hppFile · 0.80
get_dateMethod · 0.80
to_stringMethod · 0.80
to_stringMethod · 0.80
to_stringMethod · 0.80

Calls 9

isnegMethod · 0.95
iszeroMethod · 0.95
format_float_stringFunction · 0.85
insertMethod · 0.45
lengthMethod · 0.45
find_first_not_ofMethod · 0.45
sizeMethod · 0.45
eraseMethod · 0.45
atMethod · 0.45

Tested by 6

analyzeMethod · 0.64
messageFunction · 0.64
evaluateMethod · 0.64
evaluateMethod · 0.64
string_castFunction · 0.64