Funny issue with casting double to ulong

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 3 03:08:33 PDT 2017


On Monday, 3 July 2017 at 04:06:23 UTC, Saurabh Das wrote:
> On Monday, 3 July 2017 at 03:57:25 UTC, Basile B wrote:
>> On Monday, 3 July 2017 at 03:50:14 UTC, Saurabh Das wrote:
>>> [...]
>>
>> 6.251 has no perfect double representation. It's real value is:
>>
>>     6.21509999999999962483343551867E0
>>
>> Hence when you cast to ulong after the product by 10_000, this 
>> is the equivalent of
>>
>>     trunc(62150.9999999999962483343551867E0)
>>
>> which gives 62150
>>
>> CQFD ;-]
>
> That explains it!
>
> Thank you.

There's been a small typo in my answer. "6.251" i meant obviously 
"6.2151".
Anyway it doesn't change anything the most accurate double 
representation is well
the long number i said.


More information about the Digitalmars-d-learn mailing list