March 03, 2015
On Tuesday, 3 March 2015 at 21:14:47 UTC, Johan Engelen wrote:
> Also, where do I add tests for this?
> I could add a .d test file, where correct parsing of hex float literals are tested against binary representations.

Could David Gay's strtod() be used?
http://www.exploringbinary.com/how-strtod-works-and-sometimes-doesnt/
March 03, 2015
On Tuesday, 3 March 2015 at 22:12:39 UTC, Dan Olson wrote:
>
> Could David Gay's strtod() be used?
> http://www.exploringbinary.com/how-strtod-works-and-sometimes-doesnt/

Well... :(
https://github.com/JohanEngelen/ldc/commit/417cded588bcd8cf5a783ac0da731dfd53048b5d
;-)

After adding proper rounding and overflow, I think it is done. It already works well on more normal input.
March 04, 2015
On Tuesday, 3 March 2015 at 22:12:39 UTC, Dan Olson wrote:
>
> Could David Gay's strtod() be used?
> http://www.exploringbinary.com/how-strtod-works-and-sometimes-doesnt/

Thanks for that link. I had a look at David Gay's strtod() (a
complicated piece of code) and it also accepts hex floats [1].
I think it is clear that my hex parser is much simpler but also
more naive and may need quite some extra complication to make it
deal with all corner cases (I am by no measure an expert on IEEE
fp). Although a fun exercise, I guess I should accept the fact
that David Gay's function is very much superior to mine :)

Should we replace MSVC's strtod() altogether with David Gay's, or
use only the hex parser "gethex()"?
March 05, 2015
"Johan Engelen" <j@j.nl> writes:

> On Tuesday, 3 March 2015 at 22:12:39 UTC, Dan Olson wrote:
>>
>> Could David Gay's strtod() be used? http://www.exploringbinary.com/how-strtod-works-and-sometimes-doesnt/
>
> Thanks for that link. I had a look at David Gay's strtod() (a complicated piece of code) and it also accepts hex floats [1]. I think it is clear that my hex parser is much simpler but also more naive and may need quite some extra complication to make it deal with all corner cases (I am by no measure an expert on IEEE fp). Although a fun exercise, I guess I should accept the fact that David Gay's function is very much superior to mine :)
>
> Should we replace MSVC's strtod() altogether with David Gay's, or
> use only the hex parser "gethex()"?

Personally I don't know but it does look like the gethex() function could be used.  I would think whatever is easiest to keep going and passes unittests.  BTW, David Gay is listed as the author in BDS man page for strtod (uses by OS X).

Another thing.  Kai has worked on using LLVM'S own float (APFloat) support class.  Seem to me like this will eventually be the best way to go as it does all this and will be consistent across platforms.  Clang appears to use this to parse float literals (I just grepped the source).

P.S. exploringbinary is a fun website.
March 06, 2015
On Thursday, 5 March 2015 at 05:00:04 UTC, Dan Olson wrote:
> "Johan Engelen" <j@j.nl> writes:
>
>> On Tuesday, 3 March 2015 at 22:12:39 UTC, Dan Olson wrote:
>>>
>>> Could David Gay's strtod() be used?
>>> http://www.exploringbinary.com/how-strtod-works-and-sometimes-doesnt/
>>
>> Thanks for that link. I had a look at David Gay's strtod() (a
>> complicated piece of code) and it also accepts hex floats [1].
>> I think it is clear that my hex parser is much simpler but also
>> more naive and may need quite some extra complication to make it
>> deal with all corner cases (I am by no measure an expert on IEEE
>> fp). Although a fun exercise, I guess I should accept the fact
>> that David Gay's function is very much superior to mine :)
>>
>> Should we replace MSVC's strtod() altogether with David Gay's, or
>> use only the hex parser "gethex()"?
>
> Personally I don't know but it does look like the gethex() function
> could be used.  I would think whatever is easiest to keep going and
> passes unittests.  BTW, David Gay is listed as the author in BDS man
> page for strtod (uses by OS X).
>
> Another thing.  Kai has worked on using LLVM'S own float (APFloat)
> support class.  Seem to me like this will eventually be the best way to
> go as it does all this and will be consistent across platforms.
>  Clang
> appears to use this to parse float literals (I just grepped the source).
>
> P.S. exploringbinary is a fun website.

Hi Dan!

Thanks for the hint! I now use the LLVM functions instead of MSVC strtold(). Maybe someone can comment on the test results?

Regards,
Kai
March 06, 2015
On Tuesday, 3 March 2015 at 22:12:39 UTC, Dan Olson wrote:
> On Tuesday, 3 March 2015 at 21:14:47 UTC, Johan Engelen wrote:
>> Also, where do I add tests for this?
>> I could add a .d test file, where correct parsing of hex float literals are tested against binary representations.
>
> Could David Gay's strtod() be used?
> http://www.exploringbinary.com/how-strtod-works-and-sometimes-doesnt/

I think we should add this to druntime. The license seems to be compatible.
(Johan has already created a pull request I am going to reuse.)

Regards,
Kai
Next ›   Last »
1 2