digitalmars.D.announce - now it's possible! printing floating point numbers at compile-time
- Stefan Koch (12/12) Dec 22 2018 Hi Guys,
- Stefan Koch (12/14) Dec 22 2018 Aww .... I am dumb ... should have waited 2 days :)
- Basile B. (7/22) Dec 22 2018 Cool, CTFE formating is something that occasionaly comes in the
- Stefan Koch (3/13) Dec 22 2018 Thanks for pointing it out, ryu however looks less fast for ctfe
- Nick Treleaven (5/11) Dec 27 2018 Great! Is the MIT license compatible with Boost? If so I suggest
- 0xEAB (7/8) Dec 30 2018 Simply put, no. The MIT license comes with the additional
- Andre Pany (6/14) Jan 04 2019 Fantastic news
- ketmar (4/15) Dec 28 2018 of course, it is not all that fancy, but i ported STB converter quite a
- Stefan Koch (9/15) Dec 30 2018 I've benchmarked it[0] against fpconv_ctfe[1] and yours is almost
- ketmar (8/8) Dec 30 2018 i think that porting Ryu will get us the fastest one (and with
- Basile B. (9/10) Dec 30 2018 It's very recent, announce on proggit is < 1 year.
- ketmar (8/18) Dec 30 2018 actually, there is a 3rd issue, which is often overlooked: conversion fr...
- H. S. Teoh (8/23) Dec 30 2018 [...]
- ketmar (3/9) Dec 30 2018 it does. but then you can simply go with writing binaries as-is -- they ...
Hi Guys, during my research on floating point numbers I came across a short and efficient implementation[0] of the grisu2 algorithm for converting floating point numbers into strings. Which I then ported into CTFEable D code. Thus enabling you to convert doubles into strings at compiletime. Cheers Stefan Koch P.S. You can find it at my fork of fpconv[1]. [0] https://github.com/night-shift/fpconv [1] https://github.com/UplinkCoder/fpconv/blob/master/src/fpconv_ctfe.d
Dec 22 2018
On Saturday, 22 December 2018 at 20:08:12 UTC, Stefan Koch wrote:Thus enabling you to convert doubles into strings at compiletime.Aww .... I am dumb ... should have waited 2 days :) Anyhow I hope that this is helpful to some of you. Please note that grisu 2 will give you representation which will convert into the same(!) floatingpoint number you passed in >92% of all possible inputs. Meaning you can round trip from string to double without loss of bits, for very many number but not all of them, that said the accuracy in general should be better than what a usual sprintf would give you. Cheers and Merry Christmas, Stefan
Dec 22 2018
On Saturday, 22 December 2018 at 20:24:46 UTC, Stefan Koch wrote:On Saturday, 22 December 2018 at 20:08:12 UTC, Stefan Koch wrote:Cool, CTFE formating is something that occasionaly comes in the forum. Now i remember there's also RYU [1] that could have worked tooThus enabling you to convert doubles into strings at compiletime.Aww .... I am dumb ... should have waited 2 days :)No because actually from a pagan point of view the big thing was yesterday night (solstice).Anyhow I hope that this is helpful to some of you. Please note that grisu 2 will give you representation which will convert into the same(!) floatingpoint number you passed in >92% of all possible inputs. Meaning you can round trip from string to double without loss of bits, for very many number but not all of them, that said the accuracy in general should be better than what a usual sprintf would give you. Cheers and Merry Christmas, Stefan[1] https://github.com/ulfjack/ryu
Dec 22 2018
On Saturday, 22 December 2018 at 21:06:48 UTC, Basile B. wrote:On Saturday, 22 December 2018 at 20:24:46 UTC, Stefan Koch wrote:Thanks for pointing it out, ryu however looks less fast for ctfe purposes.On Saturday, 22 December 2018 at 20:08:12 UTC, Stefan Koch wrote:Cool, CTFE formating is something that occasionaly comes in the forum. Now i remember there's also RYU [1] that could have worked too [1] https://github.com/ulfjack/ryuThus enabling you to convert doubles into strings at compiletime.
Dec 22 2018
On Saturday, 22 December 2018 at 20:08:12 UTC, Stefan Koch wrote:I came across a short and efficient implementation[0] of the grisu2 algorithm for converting floating point numbers into strings. Which I then ported into CTFEable D code. Thus enabling you to convert doubles into strings at compiletime.Great! Is the MIT license compatible with Boost? If so I suggest we include it in Phobos. I remember Andrei was calling for a Grisu port for CTFE some years ago, but I think licensing of non-D implementations at the time was an issue.
Dec 27 2018
On Thursday, 27 December 2018 at 12:46:06 UTC, Nick Treleaven wrote:Is the MIT license compatible with Boost?Simply put, no. The MIT license comes with the additional requirement of including the copyright notice and license in all copies (incl. binary form), whereas BSL-1.0 requires this only for source form. PS: I am not a lawyer.
Dec 30 2018
On Sunday, 30 December 2018 at 15:14:08 UTC, 0xEAB wrote:On Thursday, 27 December 2018 at 12:46:06 UTC, Nick Treleaven wrote:Fantastic news https://github.com/night-shift/fpconv/blob/master/license night-shift was so kind to release it under boost license. Kind regards AndreIs the MIT license compatible with Boost?Simply put, no. The MIT license comes with the additional requirement of including the copyright notice and license in all copies (incl. binary form), whereas BSL-1.0 requires this only for source form. PS: I am not a lawyer.
Jan 04 2019
Stefan Koch wrote:Hi Guys, during my research on floating point numbers I came across a short and efficient implementation[0] of the grisu2 algorithm for converting floating point numbers into strings. Which I then ported into CTFEable D code. Thus enabling you to convert doubles into strings at compiletime. Cheers Stefan Koch P.S. You can find it at my fork of fpconv[1]. [0] https://github.com/night-shift/fpconv [1] https://github.com/UplinkCoder/fpconv/blob/master/src/fpconv_ctfe.dof course, it is not all that fancy, but i ported STB converter quite a long time ago, and it is ctfe-able too. ;-) [0] https://repo.or.cz/iv.d.git/blob_plain/HEAD:/ctfefloat.d
Dec 28 2018
Hi Ketmar, thanks for sharing your work! On Friday, 28 December 2018 at 19:03:02 UTC, ketmar wrote:Stefan Koch wrote:I've benchmarked it[0] against fpconv_ctfe[1] and yours is almost as fast! However it has a a little more error when converting floats than grisu2 has. Meaning generally the output cannot round-trip. Warm greetings, Stefan[ ... ] [1] https://github.com/UplinkCoder/fpconv/blob/master/src/fpconv_ctfe.dof course, it is not all that fancy, but i ported STB converter quite a long time ago, and it is ctfe-able too. ;-) [0] https://repo.or.cz/iv.d.git/blob_plain/HEAD:/ctfefloat.d
Dec 30 2018
i think that porting Ryu will get us the fastest one (and with smaller/easier code). and without pathological cases of grisu too. too bad that i didn't knew about Ryu back than. as for roundtrips -- you're probably right. stb implementation was made to be "mostly correct", afair, but not fully correct. or i broke something (which is very possible). it worked for my cases, tho, so i just sticked with it. anyway, two is better than one! ;-)
Dec 30 2018
On Sunday, 30 December 2018 at 12:19:19 UTC, ketmar wrote:too bad that i didn't knew about Ryu back than.It's very recent, announce on proggit is < 1 year. It would be nice to have one to format in phobos. RYU or Grisu3 doesn't matter much as long as the two issues that are - CTFE formatting of floats - formatting is identical on all platforms is solved. There's also the "real" problem. I'm pretty sure that 32 and 64 bits floats are always handled. Someteimes 128 bits ones but not sure for 80 bits...
Dec 30 2018
Basile B. wrote:On Sunday, 30 December 2018 at 12:19:19 UTC, ketmar wrote:actually, there is a 3rd issue, which is often overlooked: conversion from string to float. to get a perfect roundtrip, this one should be done right too.too bad that i didn't knew about Ryu back than.It's very recent, announce on proggit is < 1 year. It would be nice to have one to format in phobos. RYU or Grisu3 doesn't matter much as long as the two issues that are - CTFE formatting of floats - formatting is identical on all platformsis solved. There's also the "real" problem. I'm pretty sure that 32 and 64 bits floats are always handled. Someteimes 128 bits ones but not sure for 80 bits...80 bits can (usually) be extended to 128. you'll get some extra meaningless digits, of course, but it is better than nothing, i think. actually, Ryu has all the math to derive 80-bit implementation. it will require 128-bit integers, though. (less than 128, but there is no sense in using smaller ints anyway).
Dec 30 2018
On Sun, Dec 30, 2018 at 03:26:33PM +0200, ketmar via Digitalmars-d-announce wrote:Basile B. wrote:[...] Doesn't hex output format (e.g. std.format's %a and %A) already solve this? It basically outputs the exact bits in hex. No room for error there. T -- It said to install Windows 2000 or better, so I installed Linux instead.On Sunday, 30 December 2018 at 12:19:19 UTC, ketmar wrote:actually, there is a 3rd issue, which is often overlooked: conversion from string to float. to get a perfect roundtrip, this one should be done right too.too bad that i didn't knew about Ryu back than.It's very recent, announce on proggit is < 1 year. It would be nice to have one to format in phobos. RYU or Grisu3 doesn't matter much as long as the two issues that are - CTFE formatting of floats - formatting is identical on all platforms
Dec 30 2018
H. S. Teoh wrote:it does. but then you can simply go with writing binaries as-is -- they are not really less readable than hex floats. ;-) but we want decimals! ;-)actually, there is a 3rd issue, which is often overlooked: conversion from string to float. to get a perfect roundtrip, this one should be done right too.Doesn't hex output format (e.g. std.format's %a and %A) already solve this? It basically outputs the exact bits in hex. No room for error there.
Dec 30 2018