Issue 17628 - formattedWrite is impure on double
Summary: formattedWrite is impure on double
Status: RESOLVED DUPLICATE of issue 7438
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords:
: 15321 (view as issue list)
Depends on:
Blocks:
 
Reported: 2017-07-09 20:47 UTC by Bolpat
Modified: 2019-12-07 14:03 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Bolpat 2017-07-09 20:47:42 UTC
pure void main()
{
    import std.format : formattedWrite;
    auto app = appender!string;
    app.formattedWrite!"%s"(1.0);
}

fails. formattedWrite can purely do its job for int and string. It should also do for floating point types.
Comment 1 Vladimir Panteleev 2017-07-10 21:34:34 UTC
Missing:
    import std.array : appender;

Seems to be impure because it calls snprintf (which I think may change FPU flags or something).
Comment 2 Seb 2017-07-10 22:52:07 UTC
> which I think may change FPU flags or something

A hack would to create a pureSnprintf which resets errno to the value before its execution.

There are talks about doing this for free:

https://github.com/dlang/druntime/pull/1836
Comment 3 Eduard Staniloiu 2018-04-19 15:09:00 UTC
Since `pureMalloc`, `pureCalloc` and `pureFree` got accepted[0], maybe we could do the same for `sprintf` and `snprintf`?

[0] - https://github.com/dlang/druntime/pull/1836
Comment 4 berni44 2019-10-22 10:49:02 UTC
*** Issue 15321 has been marked as a duplicate of this issue. ***
Comment 5 berni44 2019-12-07 14:03:18 UTC

*** This issue has been marked as a duplicate of issue 7438 ***