Forum
Wrong math (solved) - Printable Version

+- Forum (https://www.boriel.com/forum)
+-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11)
+---- Forum: Bug Reports (https://www.boriel.com/forum/forumdisplay.php?fid=15)
+---- Thread: Wrong math (solved) (/showthread.php?tid=2490)



Wrong math (solved) - zarsoft - 11-08-2023

PRINT SIN 1
Gives: 0.841461181640625 (wrong)

LET v = 1
PRINT SIN v
Gives: 0.84147098 (right)


RE: Wrong math - boriel - 11-12-2023

They are actually the same value. It's a matter of precission.
SIN 1 is being calculated directly by the compiler in compiling time.
SIN(1) is aprox 0.8414709848078965

The 2nd case is computed in runtime, using the ROM calculator.

I guess this is due to a bug in precision converting from PC to ZX Spectrum 5 bytes format.
Will investigate this and keep you posted.

Thanks


RE: Wrong math - boriel - 01-03-2024

In effect, is a silly bug: for some reason, the compiler is convertig SIN 1 to Fixed before printing it.
You can (for the moment) workaround it with:
Code:
PRINT CAST(Float, SIN 1)



RE: Wrong math - boriel - 01-03-2024

Ok. Download this new beta, that fixes this issue:
http://www.boriel.com/files/zxb/zxbasic-v1.17.3-beta1.tar.gz
http://www.boriel.com/files/zxb/zxbasic-v1.17.3-beta1.zip
http://www.boriel.com/files/zxb/zxbasic-v1.17.3-beta1-win32.zip
http://www.boriel.com/files/zxb/zxbasic-v1.17.3-beta1-linux64.tar.gz
http://www.boriel.com/files/zxb/zxbasic-v1.17.3-beta1-macos.tar.gz


RE: Wrong math - zarsoft - 01-03-2024

Thanks