Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh converts a floating-point number to string with too much precision

On Sat, Dec 21, 2019 at 7:11 PM Stephane Chazelas
<stephane.chazelas@xxxxxxxxx> wrote:
> 2019-12-21 17:56:18 +0000, Stephane Chazelas:
> > 2019-12-21 10:43:43 +0100, Roman Perepelitsa:
> > [...]
> > > There is no simple algorithm that achieves this. I recall reading long
> > > papers a few years back that were describing various inventions in
> > > this field. They were pretty scary.
> >
> > https://github.com/openjdk/jdk/blob/f4af0eadb6eaf9d9614431110ab7fc9c1588966d/src/java.base/share/classes/jdk/internal/math/FloatingDecimal.java#L424
> > is not exactly trivial. I enjoyed reading the comments even if I
> > have not clue what the the code is doing.
> [...]
> Microsoft's STL implementation (to_chars) looks about as hairy:
> https://github.com/microsoft/STL/blob/264b0d4a167daa9e5499af6d783c9ff22f7af03f/stl/inc/charconv

Note that different implementations can have different behavior in
some cases. I believe the C++ spec unambiguously defines string
representation for every number but Java may not be following that
spec (it has no reason to). I recall lengthy discussions when to_chars
was being standardized. I don't remember the details but I think there
was more than one reasonable specification and judgement call had to
be made. I pointed to to_chars from the C++ standard not because it's
the best but because it's precise and recent enough to take into
account experience from other languages. It's always nice when you can
piggyback on a standard.


Messages sorted by: Reverse Date, Date, Thread, Author