Question/request/bug(?) re. floating-point in dmd

Apollo Hogan apollo.hogan at gmail.com
Wed Oct 23 13:59:48 PDT 2013


On Wednesday, 23 October 2013 at 19:10:22 UTC, Walter Bright 
wrote:
> On 10/23/2013 11:39 AM, Apollo Hogan wrote:
>> There are a couple of points here:
>>
>> - it seems that whatever the semantics of floating-point 
>> arithmetic, they should
>> be the same at compile-time as at run-time.
>
> It's not very practical, especially considering that the 
> compile time environment may be not at all the same as the 
> runtime one.

Understood, but it certainly was a surprising result to me that 
compiling and running the program on the same platform I got 
different results for a static vs. non-static variable 
initialization... (My version of PI as 
3.14159265358979311594779789241 was a bit confusing...)

> It's not that bad. You can also force a reduction in precision 
> by calling a function like this:
>
>     double identity(double d) { return d; }
>
> and ensuring (via separate compilation) that the compiler 
> cannot inline calls to identity().

Thanks, a useful trick.  It at least lets me confound the 
optimizer a bit.  (Though doesn't help with the compile vs. run 
headache.  Though this seems to be workaroundable by using a 
static constructor.  Yeah, I'm a noob.)

Thanks for the replies,
--Apollo



More information about the Digitalmars-d mailing list