pure format

Ali Çehreli via Digitalmars-d digitalmars-d at puremagic.com
Thu Jun 4 11:08:08 PDT 2015


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.

Ali



More information about the Digitalmars-d mailing list