Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function INT not working correctly
#1
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
Reply
#2
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()).
Reply
#3
I'd forgotten that, but it's true! I always thought that was a bizarre option for negative numbers.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)