zxbasic icon indicating copy to clipboard operation
zxbasic copied to clipboard

[Bug]: Differnt results from equivalent math operations

Open NMMT76 opened this issue 1 month ago • 0 comments

Contact Details

No response

Compiler version

v.1.18.4

What happened?

First off, thank you for ZX Basic, without it I'd never have gotten so far on my "virtual expansion device" work ( Zero-EM )

Now onto the issue. As i was writing/testing some new webcam related functions in Zero-EM i came across a strange behavior, so i dug a bit deeper.

As you can see from the example, two different results for an equivalent operation. My guess is that the - sign at the beginning of the first one forces some sort of type expansion/coercion that doesn't happen on the second.

While its easy to work around it, by only using INTEGER's or "hinting" at the need for type expansion/coercion, its still "unexpected behavior".

DIM adjbri,adjcon,adjgam as UBYTE
adjbri=99
adjcon=99
dim brires,conres as INTEGER

CLS

brires=-100+adjbri
conres=-100+adjcon
Print at 0,0;"Bri:";str(brires);" Con:";str(conres)
brires=adjbri-100
conres=adjcon-100
Print at 1,0;"Bri:";str(brires);" Con:";str(conres)

Kind regards and many thanks for your work

Error and Warning messages


Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

NMMT76 avatar Dec 11 '25 18:12 NMMT76