Casting double to ulong weirdness

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Mon Aug 24 12:18:42 PDT 2015


On Mon, Aug 24, 2015 at 07:15:43PM +0000, bachmeier via Digitalmars-d wrote:
> On Monday, 24 August 2015 at 18:59:58 UTC, Steven Schveighoffer wrote:
> >All this gets down to: FP cannot accurately represent decimal. Should
> >this be fixed? Can it be fixed? I don't know. But I would be very
> >cautious about converting anything FP to integers without some
> >epsilon.
> >
> >-Steve
> 
> I don't see anything that needs to be fixed, because I don't think
> anything is broken - there is nothing that violates my understanding
> of floating point precision in D.
> 
> cast is not round. What is broken is a program that attempts to
> convert a double to an integer type using a cast rather than the
> functions that were written to do it correctly.

+1.

Floating-point != mathematical real numbers. Don't expect it to behave
the same.


T

-- 
It's amazing how careful choice of punctuation can leave you hanging:


More information about the Digitalmars-d mailing list