Repository navigation
[core] Remove trailing zeros in float→string conversion - #4965
friedbunny wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
Other things to test:
0→0-0→-0(not sure about this one)10→10-10→-10
There was a problem hiding this comment.
Did this in d09cdb4a2dbc53ff2515e09777b17beed2c57b8f.
If a float looks sufficiently int-like, cast as int and be done. Otherwise, let std::to_string() convert the float to a string, then trim trailing zeros and hanging decimal points.
This allows smaller types to avoid unnecessary formatting, besides theoretically making these casts safer.
d09cdb4 to
272f75e
Compare
Avoid some manual text processing in hopes of being more robust. Updated tests to reflect a default precision of six significant figures.
|
@jfirebaugh, would there be any disadvantage to using |
|
Remember to update all the relevant changelogs. |
|
I think using
|
Has anyone been able to reproduce this issue in iOS SDK v3.2.1? If not, there’s no need to backport the fix, it may be too late for 3.2.2 anyways. |
|
We don’t need this for v3.2.x — I think I had a bork build at one point that did suffer from this issue, but subsequent builds and the RC work as expected. |
|
Can we use RapidJSON's dtoa.h implementation instead of |
|
If we're concerned about performance, perhaps |
|
@1ec5 See https://github.com/miloyip/dtoa-benchmark and https://github.com/miloyip/itoa-benchmark for benchmarks. |
|
I'm interested in optimizing this because I've seen this be a bottleneck in the past, because we're doing a lot of number => string conversions when parsing tiles. |
|
Unassigned myself — this can be implemented more efficiently and precisely by someone else. |
|
Superseded by #5054. |
With the replacement of
boost::lexical_castwithstd:to_stringin #4916, symbol labels that used floating point numbers could end up looking like “12345.000000” when the passed in number was actually just “12345”.The fix here is two-fold:
std::to_stringconvert the float to a string, then trim trailing zeros and hanging decimal points.If this passes muster, we should consider including it in iOS v3.2.2 and the next Android release.
Fixes #998.
/cc @jfirebaugh @1ec5 @tobrun