double vs real

Diggory diggsey at googlemail.com
Thu May 30 09:37:43 PDT 2013


On Thursday, 30 May 2013 at 16:18:44 UTC, Shriramana Sharma wrote:
> Hello. I like that D exposes to me the real type to maximally 
> utilize
> the machine's numerical precision. Since I am writing a program
> (currently in C++ but I am thinking of moving to D) that has to 
> handle
> lots of fractional numbers (calculating offset curves and such) 
> I am
> wondering whether/when I should real instead of double or even 
> any
> arguments in favour of staying with double (compatibility with
> C/C++?). Any pointers appreciated please? I checked the FAQ but 
> it
> doesn't seem to mention this.
>
> Thanks!

Since D does all operations at highest possible precision anyway 
(even for double or float) it only makes a difference when the 
value is being stored to memory and then read back again.

I would recommend aliasing double or real to a custom name and 
then using that. Then when you're done you can easily switch 
between them and see how it affects precision in your particular 
case and decide what's best.


More information about the Digitalmars-d-learn mailing list