Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
September 26, 2015 Purity of std.conv.to!string | ||||
---|---|---|---|---|
| ||||
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. |
September 26, 2015 Re: Purity of std.conv.to!string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | 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.
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.
|
September 26, 2015 Re: Purity of std.conv.to!string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | 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.
I don't know the exact reason but I found a couple of functions which could be marked pure which are not, including strippedOctalLiteral and isOctalLiteralString. It's possible that some function was simply overlooked and needs to be marked pure or infer purity.
The larger issue at hand is that the compiler doesn't tell you where an impurity lies, merely that it exists. I mentioned this issue not too long ago while experiencing my own difficulties respecting purity.
|
September 27, 2015 Re: Purity of std.conv.to!string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | 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. Please make an issue on https://issues.dlang.org and I'll take a look a this later. Most of the functions in std.conv are templated so it must be some internal function that's not properly annotated, or it's using manual memory management. |
September 27, 2015 Re: Purity of std.conv.to!string | ||||
---|---|---|---|---|
| ||||
Posted in reply to cym13 | 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. |
September 28, 2015 Re: Purity of std.conv.to!string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jack Stouffer | On Sunday, 27 September 2015 at 05:52:26 UTC, Jack Stouffer wrote: > Please make an issue on https://issues.dlang.org and I'll take a look a this later. Most of the functions in std.conv are templated so it must be some internal function that's not properly annotated, or it's using manual memory management. Already file here: https://issues.dlang.org/show_bug.cgi?id=3437 https://issues.dlang.org/show_bug.cgi?id=4850 |
Copyright © 1999-2021 by the D Language Foundation