Forum
function INT not working correctly - 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: function INT not working correctly (/showthread.php?tid=471)



function INT not working correctly - frisian - 06-20-2012

I recently discovered ZX Basis Compiler and this forum and it brought back some memories off the days that i owned and used a ZX Spectrum (48k and later a 128k) . I have collected some emulators over the years so i tried to compile some programs, one off witch made a little drawing using some calculation, it look a little different from the normal basic version.

It comes down to converting a float to a integer.

INT 3.9 gives 3 in normal basic and compiled
INT -3.9 in normal basic this is -4 but compiled the answer is -3
The correct answer is -4 according to the ZX basic manual (and also according other programming languages )

I tried zxb .exe version 1.2.9-s758 and zxb version 1.2.9-s882

this problem also occurrence with CAST(integer,float)

Regards


Re: function INT not working correctly - boriel - 06-26-2012

Hmmm. That's right! Just read ZX Spectrum Manual, Chapter 9
What a dilemma. Should we use INT for truncation or the way ZX Spectrum manual says?
I suppose we must mimic Sinclair BASIC, and add extra math functions for alternative roundings? (e.g. the INT behaviour you point is equivalent to C floor()).


Re: function INT not working correctly - britlion - 06-26-2012

I'd forgotten that, but it's true! I always thought that was a bizarre option for negative numbers.