Question:
Does this mean: In WIN 32bit and Linux 32bit not only the calculation of 'x+k' is done with extended (80bit) precision - then the result is passed to the int() function also with 80bit precision? - without converting the result of 'x+k' between to double?
If yes, I would understand and would have learned a lot.
Yes:
lea esp, [esp - 12]
fstp TBYTE PTR [esp]
call <fpc_int_real>
This is the disassembly of the 32-bit Windows code that passes the result of x+k to fpc_int_real with all 80 bits intact (as evidenced by the presence of TBYTE PTR).
Thanks a lot for this clear and helpful answer. As you see, I'm not only interested to find a solution (which I yet have 2 different since reply #4), I'm also interested to learn something and invest a lot of time for this, because this will become reply #23.
I linked to this specific answer in that thread (which I basically restated in the rest of my answer):
When the OS sets up a process (or thread) -- say, when your program launches, it is responsible for initializing the control registers to the default state (exactly what the default state is can vary somewhat from platform to platform). It is also responsible for saving and restoring state around context switches, so that your program doesn't bleed state into some other process that is also running on the system.
Beyond that, a compiler or a language runtime might modify the state before your code is executed.
As said, your Link was about Microsoft Visual C++ 2008 on
Windows. I could not see, whether this has any relevance for my issue on
Linux.
Wasn't your first question about wanting to understand why there are platform differences...?
You are right, my question was not precise enough. You showed me, *where* the switch is done, which causes the difference between 32bit and 64bit. My question was more intended to understand the differences in the *behaviour* between 32bit and 64 bit, when/how (internal) calculations are computed. That's on me asking not clear enough, sorry for confusion. But due to the answers of avk and you now I understand.
- why does SetRoundMode(rmDown) "repair" the rounding issue in math.SimpleRoundTo() on Linux 64bit, although it's rounding behaviour is not changed by that? Does SetRoundMode(rmDown) have a hidden "side affect"?
SetRoundMode calls Set8087CW, so yes, it does have a side effect - across your entire program and every single floating-point operation it performs.
This function does not just influence Round or SimpleRoundTo in particular.
That sounds interesting.
I checked the official documentation for 'Set8087CW' in
https://www.freepascal.org/docs-html/current/rtl/system/set8087cw.html which only says:
Set8087CW
Declaration
Source position: mathh.inc line 21
procedure Set8087CW(
cw: Word);
And I checked the sources both in line 21 of <installdir>/fpcsrc/rtl/inc/mathh.inc and line 51 in <installdir>/fpcsrc/rtl/x86_64/math.inc but this is ASM-Code beyond my horizon.
BTW: I did this check for 'Set8087CW' also 2 days ago, before writing reply #6, before posting there the source of function SetRoundMode(). So your criticism
But instead of putting in even a modicum of effort to educate yourself, you expect to be spoonfed all the way.
is not applicable.
If you already know more about this "side affect" caused by Set8087CW() - what are those differences for "the entire program and every single floating-point operation it performs" -
and if you want to write something about that, I would appreciate this.
But in this Forum nobody is forced to write something, if he does not want to. Even if he knows the answer, but only assumes, that for his criterion the questioner does not invest enough effort, to answer his questions by himself.
Since I found this rounding issue 6 days ago, I spent 100% of my freetime for it. First trying to understand and solve it by myself (in my 1st post you can see, how much I investigated and found out by myself), than starting and maintaining this Topic. Maybe you have unlimited freetime. Unfortunately I have not.