[Glass] Faster Float printing possible?

Martin McClure via Glass glass at lists.gemtalksystems.com
Wed Feb 8 12:41:30 PST 2017


On 02/08/2017 11:59 AM, Mariano Martinez Peck via Glass wrote:
> On Wed, Feb 8, 2017 at 3:31 PM, Dale Henrichs via Glass
> <glass at lists.gemtalksystems.com
> <mailto:glass at lists.gemtalksystems.com>> wrote:
>
>     Mariano,
>
>     Float>>asString is implemented as a primitive and you could
>     probably use that call just about anywhere you want ... I am not a
>     floating point guy,
>
>
> Where is Martin when we need him?? hahahahahhaa
>  
>
>     so I cannot comment on where you will see differences in the
>     output strings (if any at all) and of course I don't know how
>     important precision is when you are passing around json ...
>
>
> Thanks Dale. That indeed gives me like .. around 2x performance
> improvement. As for the results, for JSON it looks like correct. But I
> would love to hear if Martin has something else to comment on.
>
Hi Mariano,

I guess I have something of a reputation. :-)

Printing binary floats in decimal is a surprisingly complex topic, with
quite a few papers published on the topic.

I haven't looked at your case in detail (especially the JSON conversion)
but IIRC the Float>>asString primitive uses a double printing routine in
libc, which should be both fast and accurate. Though there *was* for
several years a bug in glibc that made it print an insufficient number
of digits for a small percentage of floats, so that when read back in
the resulting float was one LSB off from the original float. That was
fixed in glibc several years ago, so recent Linux distributions should
do correct printing now.

Regards,

-Martin

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gemtalksystems.com/mailman/private/glass/attachments/20170208/76375070/attachment.html>


More information about the Glass mailing list