Why is to(T) pure but roundTo(T) impure?
    Chris Saunders 
    sencha at gmail.com
       
    Sat Jun  9 11:43:42 PDT 2012
    
    
  
Hi --
I've been trying to learn more about D's purity features after 
reading David Nadlinger's interesting post on this topic. While 
'purifying' some existing code I discovered that I can't use 
roundTo in a pure function, and I don't understand why. Is this a 
general problem with most floating-point library calls? (e.g. I 
noticed std.math.floor() is impure as well).
"""
import std.conv;
int func(double d) pure {  // compiles...
	return to!int(d);
}
int func2(double d) pure {  //doesn't compile!?!
	return roundTo!int(d);
}
"""
Thanks for any pointers!
-Chris
    
    
More information about the Digitalmars-d-learn
mailing list