Purity of std.conv.to!string

Daniel Murphy via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Sep 27 07:15:48 PDT 2015


On 27/09/2015 3:14 AM, cym13 wrote:
> On Saturday, 26 September 2015 at 17:08:00 UTC, Nordlöw wrote:
>> Why is the following code not pure:
>>
>>     float x = 3.14;
>>     import std.conv : to;
>>     auto y = x.to!string;
>>
>>
>> ???
>>
>> Is there a reason for it not being pure? If not, this is a serious
>> problem as this is such a fundamental function.

Probably because it uses C's float formatting functions, and they 
probably set errno and therefore aren't pure.

>
> Maybe because of floating point numbers uncertainty that would cause the
> resulting string to be different for two equivalent inputs? I can't seem
> to put an example together though.

No, it doesn't work like that.


More information about the Digitalmars-d-learn mailing list