summaryrefslogtreecommitdiff
path: root/gr-qtgui/lib/edit_box_msg_impl.cc
diff options
context:
space:
mode:
authorThomas Habets <thomas@habets.se>2020-04-03 15:24:49 +0100
committerMarcus Müller <marcus@hostalia.de>2020-04-11 02:39:54 +0200
commit3bab5f023ab406b9a4521e7c3be7fd4bd33135f7 (patch)
tree4b1e21191d16653afb7c1ed233d9c6ef8bf170f9 /gr-qtgui/lib/edit_box_msg_impl.cc
parent3cb8a09e065f39e2b6db444d62f756dc03bf332d (diff)
qtgui: Remove boost::lexical_cast for printing
boost::lexical_cast seems not not be consistent given different inputs. E.g. std::complex is stringified like iostream, but float and double avoid scientific notation… mostly. See below for comparisons between before and after (`printf` is what this commit switches to). I don't think the differences matter. ``` int main() { constexpr float low_float = 200000000.2; constexpr float high_float = 20000000000.2; constexpr float low_double = 200000000.2; constexpr float mid_double = 20000000000.2; constexpr float high_double = 200000000000000000.2; const std::complex<float> c(1.3,low_float); const std::complex<double> d(1.3,low_double); const std::complex<double> d2(1.3,high_double); const std::vector<float> fs = {low_float, high_float}; const std::vector<double> ds = {low_double, mid_double, high_double}; std::cout << "# complex\n"; std::cout << "iostream: " << c << std::endl; std::cout << "lexical_cast: " << boost::lexical_cast<std::string>(c) << std::endl; std::cout << std::endl; for (int i = 0; i < fs.size(); i++) { std::cout << "# float " << i << std::endl; std::cout << "iostream: " << fs[i] << std::endl; std::cout << "to_string: " << std::to_string(fs[i]) << std::endl; printf("printf %.f\n", std::numeric_limits<float>::digits10, fs[i]); std::cout << "lexical: " << boost::lexical_cast<std::string, float>(fs[i]) << std::endl; std::cout << std::endl; } for (int i = 0; i < ds.size(); i++) { std::cout << "# double " << i << std::endl; std::cout << "iostream: " << ds[i] << std::endl; std::cout << "to_string: " << std::to_string(ds[i]) << std::endl; printf("printf %.*g\n", std::numeric_limits<double>::digits10, ds[i]); std::cout << "lexical: " << boost::lexical_cast<std::string, double>(ds[i]) << std::endl; std::cout << std::endl; } } ``` Output (Debian amd64): ``` iostream: (1.3,2e+08) lexical_cast: (1.3,2e+08) iostream: 2e+08 to_string: 200000000.000000 printf 200000000 lexical: 200000000 iostream: 2e+10 to_string: 20000000000.000000 printf 20000000000 lexical: 2e+10 iostream: 2e+08 to_string: 200000000.000000 printf 200000000 lexical: 200000000 iostream: 2e+10 to_string: 20000000000.000000 printf 20000000000 lexical: 20000000000 iostream: 2e+17 to_string: 199999996861349888.000000 printf 1.9999999686135e+17 lexical: 1.9999999686134989e+17 ```
Diffstat (limited to 'gr-qtgui/lib/edit_box_msg_impl.cc')
0 files changed, 0 insertions, 0 deletions