<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Apr 18, 2020 at 5:50 AM <<a href="mailto:rmrodriguez@carto.com">rmrodriguez@carto.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
> A proposal that fixes this problem, has relatively simple semantics, and doesn't require changing the precision default value is:<br>
<br>
Yesterday I spent some time looking into ryu's smallest round-trip<br>
string, and I think it's simpler and hopefully doable without too much<br>
complication to have a single common semantic for all double printing:<br>
Print only as many digits as necessary to fulfill round-trip<br>
conversion, but limit the amount of decimal digits to the ones<br>
requested by the user.<br></blockquote><div><br></div><div>When you say "limit" do you mean truncate or round?   I don't think truncation is a good approach (based on what every other precision-limiting system I have seen does).  </div><div><br></div><div>If you mean round then I *think* your suggestion is essentially the same as mine.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
This gives us several things:<br>
- The output is guaranteed to be the shortest possible, without losing<br>
information when imported back.<br>
- Requesting precision >= 17 is probably meaningless, since at most we<br>
are printing 17 digits for 64bit doubles. I think that once the round<br>
trip is guaranteed, nobody will need a 20 or 30 decimal precision<br>
since you can't (or shouldn't) operate on strings.<br></blockquote><div><br></div><div>Agreed</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
- Requesting precision < 15 will still have some use, especially<br>
things like precision 0..4.<br></blockquote><div><br></div><div>I would say precision 0..8 is most useful; beyond that not as much.  </div><div><br></div><div>But surely there has to be some transition point at which rounding stops and "full" precision is used?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
- There is no artificial distinction between < 15 and > 15, which<br>
eliminates inconsistencies. Note that in your proposal you would get<br>
odd things like this:<br>
  - 0.300000011920928955078125 with precision 10 -> 0.3000000119<br>
  - 0.300000011920928955078125 with precision 20 -> 0.3 (since 0.3 has<br>
the same double representation)<br></blockquote><div><br></div><div>I don't see how  0.300000011920928955078125 has the same DP representation as 0.3. DP has about 16 digits of precision, so surely the first number would be represented as (close to) 0.300000011920929 ?</div></div></div>