9999999999999999.0 - 9999999999999998.0

2019-01-05 Thread Samir via Digitalmars-d-learn
I saw the following thread[1] today on Hacker News that discusses an article that compares how various languages compute .0 - 9998.0. A surprisingly large number of languages return 2 as the answer. I ran the following which returned 1: import std.stdio: writeln

Re: 9999999999999999.0 - 9999999999999998.0

2019-01-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 6 January 2019 at 00:20:40 UTC, Samir wrote: import std.stdio: writeln; void main(){ writeln(cast(double).0-9998.0); } That's because it is done at compile time, since both are compile-time constants. The compiler will evaluate it using the ma

Re: 9999999999999999.0 - 9999999999999998.0

2019-01-05 Thread Jesse Phillips via Digitalmars-d-learn
On Sunday, 6 January 2019 at 00:20:40 UTC, Samir wrote: [1] https://news.ycombinator.com/item?id=18832155 [2] https://en.wikipedia.org/wiki/IEEE_754 Since you got your answer you may also like http://dconf.org/2016/talks/clugston.html

Re: 9999999999999999.0 - 9999999999999998.0

2019-01-06 Thread Samir via Digitalmars-d-learn
On Sunday, 6 January 2019 at 01:05:08 UTC, Adam D. Ruppe wrote: That's because it is done at compile time, since both are compile-time constants. The compiler will evaluate it using the maximum precision available to the compiler, ignoring your request to cast it to double (which annoys some pe