Wrong result of inlined function
## Summary A function containing a specific mathematical calculation returns an incorrect result when the function is inlined. ## System Information - **Operating system:** Linux Mint 21.1 (no issue on Windows) - **Processor architecture:** x86-64 - **Compiler version:** FPC 3.3.1 commit 2584b5c175fdfb3eb7476304f34a68005a307eaa (I did not observe the issue on FPC 3.2.2) - **Device:** Computer ## Steps to reproduce Run the project shown below. In the function `Calc`, it calculates the value of `Power(10, Floor(Log10(0.01)))`. The appearance of this issue does not depend on the exact values of the literal numbers used. There are some combinations, though, where the inlined function returns the correct result (e.g. using 1.0 in the Log10). ## Example Project ```pascal program project1; uses Math; function Calc: Double; inline; begin Result := Power(10, Floor(Log10(0.01))); end; begin WriteLn(Calc:0:3); end. ``` ## What is the current bug behavior? The return value of the function `Calc` is wrong, when it is declared as `inline`. The output of the test project is `0.250` while it should be `0.010`. The appearance of this issue usually does not depend on the exact values of the literal numbers used. There are some combinations, though, where the inlined function returns the correct result (e.g. using 1.0 in the Log10). ## What is the expected (correct) behavior? The correct result can be calculated directly: log10(0.01) = -2, Floor(-2) = -2, Power(10,-2) = 10^-2 = 0.01. This result is obtained when the `inline` is removed from the function declaration. ## Notes * The issue does not appear on Windows, I saw it only on Linux. * The issue is tied to FPC/main, the release version does not have it. (did not test FIXES).
issue