I'd like to convert a double to a string in a pure function. I'm confused as to why this isn't pure:
wstring fromNumber(double n) pure {
import std.format;
return std.format.format!("%s"w)(n);
}
Is there a way to implement this function in a pure
way without having to reimplement the logic for converting a double to a base10 string?
so the reason it isn't pure is that the conversion depends on global information like the locale (1,4
vs 1.4
for example) and the floating point rounding flag in the CPU. the D implementation calls out to a C function which relies on these.. so i kinda think the answer is someone will have to reimplement the logic and that's non-trivial for a lot of reasons.