Re: Weird floating point rounding - Bug or how to control it correctly

2023-09-13 Thread Basile B. via Digitalmars-d-learn
On Thursday, 14 September 2023 at 03:23:48 UTC, An Pham wrote: import std.stdio; void main() { float f = 6394763.345f; import std.format : sformat; char[80] vBuffer = void; writeln("6394763.345 = ", sformat(vBuffer[], "%.4f", f));

Re: Weird floating point rounding - Bug or how to control it correctly

2023-09-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, September 13, 2023 9:23:48 PM MDT An Pham via Digitalmars-d- learn wrote: > import std.stdio; > > void main() > { > float f = 6394763.345f; > > import std.format : sformat; > > char[80] vBuffer = void; > writeln("6394763.345 = ", sformat(v

Weird floating point rounding - Bug or how to control it correctly

2023-09-13 Thread An Pham via Digitalmars-d-learn
import std.stdio; void main() { float f = 6394763.345f; import std.format : sformat; char[80] vBuffer = void; writeln("6394763.345 = ", sformat(vBuffer[], "%.4f", f)); } Output 6394763.345 = 6394763.5000

Re: Floating point rounding

2017-03-04 Thread ag0aep6g via Digitalmars-d-learn
On 03/03/2017 05:39 PM, ag0aep6g wrote: dmd generates SSE instructions for floating point math. FloatingPointControl only minds the control register for the FPU. But SSE instructions are not affected by that. SSE has a separate control register: MXCSR. I've filed an issue: https://issues.dl

Re: Floating point rounding

2017-03-03 Thread ag0aep6g via Digitalmars-d-learn
On 03/02/2017 10:49 PM, Guillaume Chatelet wrote: Thx for the investigation! Here is the code for FloatingPointControl https://github.com/dlang/phobos/blob/master/std/math.d#L4809 Other code (enableExceptions / disableExceptions) seems to have two code path depending on "version(X86_Any)", round

Re: Floating point rounding

2017-03-02 Thread Guillaume Chatelet via Digitalmars-d-learn
On Thursday, 2 March 2017 at 21:34:56 UTC, ag0aep6g wrote: On 03/02/2017 10:10 PM, Guillaume Chatelet wrote: On Thursday, 2 March 2017 at 20:30:47 UTC, Guillaume Chatelet wrote: Here is the same code in D: void main(string[] args) { import std.math; FloatingPointControl fpctrl; fpct

Re: Floating point rounding

2017-03-02 Thread ag0aep6g via Digitalmars-d-learn
On 03/02/2017 10:10 PM, Guillaume Chatelet wrote: On Thursday, 2 March 2017 at 20:30:47 UTC, Guillaume Chatelet wrote: Here is the same code in D: void main(string[] args) { import std.math; FloatingPointControl fpctrl; fpctrl.rounding = FloatingPointControl.roundUp; writefln("%.

Re: Floating point rounding

2017-03-02 Thread Guillaume Chatelet via Digitalmars-d-learn
On Thursday, 2 March 2017 at 20:30:47 UTC, Guillaume Chatelet wrote: Here is the same code in D: void main(string[] args) { import std.math; FloatingPointControl fpctrl; fpctrl.rounding = FloatingPointControl.roundUp; writefln("%.32g", float.min_normal + 1.0f); } Execution on my

Floating point rounding

2017-03-02 Thread Guillaume Chatelet via Digitalmars-d-learn
I would expect that (1.0f + smallest float subnormal) > 1.0f when the Floating Point unit is set to Round Up. Here is some C++ code: #include #include #include int main(int, char**) { std::fesetround(FE_UPWARD); printf("%.32g\n", std::numeric_limits::denorm_min() + 1.0f); retur