![]() |
¿Posible bug ? - 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: ¿Posible bug ? (/showthread.php?tid=873) |
¿Posible bug ? - maeloterkim - 03-29-2019 Hola ![]() Estoy compilando con la versión-1.8.9 de ZX BASIC y me pasa lo siguiente: Cuando pongo 10 DIM valor, sum AS UBYTE 20 LET sum = 3 30 LET valor = 1 * (sum=3) el valor debería ser solamente: 0 o 1 dependiendo del valor de sum pero devuelve 0 o 255 ( que me parece que es, el máximo valor de UBYTE) En el basic del zx spectrum si funciona correctamente Para solucionarlo pongo 30 LET valor = 1 * ( (sum=3)/255 ) y ahora si da los valores correctos, pero claro añade más procesamiento ¿Debería funcionar así o es un bug? Saludos Re: ¿Posible bug ? - boriel - 04-14-2019 Si, es normal. Es decir, por motivos de rendimiento, ZX Basic asegura que 0 es False, y "cualquier otra cosa" (normalmente -1 o sea, 255 en Ubyte) True. No sucede siempre, pero si bastantes veces. Si quieres asegurarte de que siempre True es 1, compila con el flag --strict-bool (Más info aquí: https://zxbasic.readthedocs.io/en/docs/zxb/#Command_Line_Options) Re: ¿Posible bug ? - britlion - 04-15-2019 For English Speakers passing by: Possible bug? Hello ![]() I am compiling with the version-1.8.9 of ZX BASIC and the following happens: When I put 10 DIM value, sum AS UBYTE 20 LET sum = 3 30 LET value = 1 * (sum = 3) the value should only be: 0 or 1 depending on the value of sum but it returns 0 or 255 (which I think it is, the maximum value of UBYTE) In the basic of the zx spectrum if it works correctly To fix it I put 30 LET value = 1 * ((sum = 3) / 255) and now if it gives the correct values, but of course it adds more processing Should it work like this or is it a bug? Quote:Yes it's normal. That is, for performance reasons, ZX Basic ensures that 0 is False, and "anything else" (normally -1, 255 in Ubyte) True. It does not always happen, but many times. Re: ¿Posible bug ? - britlion - 04-15-2019 For my part, I think the simplest solution would probably be: Code: LET valor = sgn (sum=3) I think that would work? 0 for 0. And 1 for any other positive value - and less calculation than dividing by 255 (and given there's no guarantee that TRUE=255, possibly safer?) Creo que la solución más simple probablemente sería: Code: LET valor = sgn (sum=3) Creo que eso funcionaria? 0 para 0. Y 1 para cualquier otro valor positivo, y menos cálculo que dividir por 255 (y dado que no hay garantía de que TRUE = 255, ¿sea más seguro?) Re: ¿Posible bug ? - boriel - 04-15-2019 Thx, Britlion! Yes, your solution works too! ![]() Re: ¿Posible bug ? - maeloterkim - 04-17-2019 Gracias Al final me di cuenta de la compilación con --strict-bool ![]() Thanks Thanks in the end I realized the compilation with --strict-bool ![]() |