bug or missunderstood? - 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: bug or missunderstood? (/showthread.php?tid=744) |
bug or missunderstood? - Haplo - 10-27-2016 Hello, if I run this program: Code: cls the output in screen is: valor:50 valor:244 valor:10000 valor:244 valor:50 valor:500 This is a bug? Re: bug or missunderstood? - boriel - 11-07-2016 hock: This definitely looks like a bug. What compiler version are you using?? Re: bug or missunderstood? - Haplo - 11-07-2016 Hello, the version is 1.4.0-s1967 Re: bug or missunderstood? - boriel - 11-07-2016 Haplo Wrote:Hello, the version is 1.4.0-s1967Phew!! :roll: It's not a bug (BTW the latest version is 1.4.0-s1968). The problem is you are declaring a and b as ubyte, and ZX Basic does not typecast by default to Uinteger if the result is uinteger. Your code: Code: cls Some compilers (e.g. most C Compilers) detects that 'valor' is Uinteger and will typecast A and B to Uinteger. ZX Basic does not, for performance reasons (Z80 and 48k are so tiny... :roll: ) You can overcome this by doing an Explicit CAST. Try this: Code: cls Most C compilers do that automatically. ZXBasic needs you to explicit use CAST in one of the operands. I'm thinking whether or not ZX Basic should follow the policy of the other compilers, but this will reduce performance (and take more memory). Re: bug or missunderstood? - Haplo - 11-08-2016 Thanks, I just update to s1968 I thought that if I declare "valor" as uinteger previously, would be enough. I used to declare the variables according their range of values, but this behavior disconcert me. By now, I will change all the ubyte variables to uinteger, avoiding the problem by this way. Re: bug or missunderstood? - boriel - 11-08-2016 Haplo Wrote:Thanks, I just update to s1968The range of valor is ok. The range of the others is not. Ok. This is something we need to discuss. Maybe is better to use the standard behaviour. Basically, in ZXBasic a * b is expanded to Uinteger *after* the multiplication. Other compilers expands first. But this is more expensive... |