digitalmars.D.learn - Does D optimize sqrt(2.0)?
- Enjoys Math (3/3) Feb 10 2016 If I just type out sqrt(2.0) in D, is that automatically made
- crimaniak (12/15) Feb 11 2016 for DMD -O :
- Johannes Pfau (4/7) Feb 11 2016 For GDC the answer is yes:
If I just type out sqrt(2.0) in D, is that automatically made into a constant for me? Thanks.
Feb 10 2016
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
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