On 6/4/15 2:08 PM, Ali Çehreli wrote:
On 06/04/2015 10:02 AM, Oleg B wrote:

 > I think toString for float must be pure, but in practice it's not.
 >
 > import std.stdio;
 > import std.string;
 > string test( float abc ) pure { return format( "abc: % 6.3f", abc ); }
 > void main() { writeln( test( 13.3 ) ); }
 >
 > $ rdmd purefmtfloating.d
 > purefmtfloating.d(3): Error: pure function 'purefmtfloating.test' cannot
 > call impure function 'std.format.format!(char, float).format'
 > Failed: ["dmd", "-v", "-o-", "purefmtfloating.d", "-I."]
 >
 > DMD64 v2.067.1
 >
 > It's a bug? I read what std.format.format using libc sprintf
 >
http://www.digitalmars.com/d/archives/digitalmars/D/learn/std.conv.to_purity_68957.html

 > and if it try it's not a bug...

Floating point operations share global state ("flags" or "attributes")
for rounding mode, exception and trap handling. Perhaps that's why
floating point format cannot be pure.

That is a terrible excuse if that is what the issue is.

I recalled Don discussing this, found these threads (they are old, maybe something has gotten better since then):

http://forum.dlang.org/post/gpddrm$20u7$1...@digitalmars.com
http://forum.dlang.org/post/h8ad5r$22jj$1...@digitalmars.com

From that, it does seem that D does not care about the rounding modes, and just considers the code pure.

-Steve

Reply via email to