www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Does D optimize sqrt(2.0)?

reply Enjoys Math <enjoysmath gmail.com> writes:
If I just type out sqrt(2.0) in D, is that automatically made 
into a constant for me?

Thanks.
Feb 10 2016
next sibling parent crimaniak <crimaniak gmail.com> writes:
On Thursday, 11 February 2016 at 07:41:55 UTC, Enjoys Math wrote:
 If I just type out sqrt(2.0) in D, is that automatically made 
 into a constant for me?

 Thanks.
for DMD -O : import std.math; immutable foo = sqrt(2.0); pure float precalculated() { return foo; } pure float not_precalculated() { return sqrt(2.0); }
Feb 11 2016
prev sibling parent Johannes Pfau <nospam example.com> writes:
On Thursday, 11 February 2016 at 07:41:55 UTC, Enjoys Math wrote:
 If I just type out sqrt(2.0) in D, is that automatically made 
 into a constant for me?

 Thanks.
For GDC the answer is yes: LDC will probably optimize this as well. Not sure about DMD.
Feb 11 2016