First Spear Posted May 7, 2018 Share Posted May 7, 2018 Hey all. From manual.txt: Using PRINT for numbers always show numbers as unsigned from 0 to 65535 I plan to store values in an array, each value one can be from -99 to 99. For debugging, since I can't PRINT the values on-screen, what is a smart way to watch the values? Thanks. Quote Link to comment Share on other sites More sharing options...
+nanochess Posted May 7, 2018 Share Posted May 7, 2018 ' Note: for use with 8-bit signed values (declare with SIGNED), for 16 bits values use #a IF a >= 0 THEN PRINT <3>,a ELSE PRINT "-",<2>-a 1 Quote Link to comment Share on other sites More sharing options...
intvnut Posted May 7, 2018 Share Posted May 7, 2018 And if nanochess' approach is too much code, why not just add a linear offset? If it really is in the range -99 to 99, just add 100 to it. You'll have to mentally subtract off the extra 100 when you read off the value, but for debug code, that's not too bad. nanochess' produces more human friendly output, though, and is also worth using for actual signed outputs that aren't just debug outputs. 2 Quote Link to comment Share on other sites More sharing options...
First Spear Posted May 7, 2018 Author Share Posted May 7, 2018 I was wondering about the linear offset, it is "better" for the sake of speed to work in 1 to 199 or -99 to 99? It's premature optimization and all that, but if there is a performance penalty I can dodge I'd like to understand the tradeoffs. Thanks. And if nanochess' approach is too much code, why not just add a linear offset? If it really is in the range -99 to 99, just add 100 to it. You'll have to mentally subtract off the extra 100 when you read off the value, but for debug code, that's not too bad. nanochess' produces more human friendly output, though, and is also worth using for actual signed outputs that aren't just debug outputs. Quote Link to comment Share on other sites More sharing options...
intvnut Posted May 7, 2018 Share Posted May 7, 2018 My approach is marginally faster. Mostly, it's a lot smaller (both in source and in executable size), and less intrusive looking. It's perhaps also harder to get wrong. For example, nanochess's THEN and ELSE clauses need to be swapped: . Before: ' Note: for use with 8-bit signed values (declare with SIGNED), for 16 bits values use #a IF a < 0 THEN PRINT <3>,a ELSE PRINT "-",<2>-a Corrected: ' Note: for use with 8-bit signed values (declare with SIGNED), for 16 bits values use #a IF a < 0 THEN PRINT "-"<2>,-a ELSE PRINT <3>-a 1 Quote Link to comment Share on other sites More sharing options...
carlsson Posted May 7, 2018 Share Posted May 7, 2018 If you want the absolute value, how would you come up with a formula for a variable in the range of 1-199 where 100 equals the mid point? I tried for a while and came up with a%100 as part of the solution but then one needs to reverse the numbers for one half of the range so the absolute value would be 99, 98 ... 2, 1, 0, 1, 2, ... 98, 99. And yes, one of my projects uses signed numbers where I use the absolute value at more than one occasion so it isn't entirely academic. Quote Link to comment Share on other sites More sharing options...
+nanochess Posted May 7, 2018 Share Posted May 7, 2018 My approach is marginally faster. Mostly, it's a lot smaller (both in source and in executable size), and less intrusive looking. It's perhaps also harder to get wrong. For example, nanochess's THEN and ELSE clauses need to be swapped: . Before: ' Note: for use with 8-bit signed values (declare with SIGNED), for 16 bits values use #a IF a < 0 THEN PRINT <3>,a ELSE PRINT "-",<2>-a Corrected: ' Note: for use with 8-bit signed values (declare with SIGNED), for 16 bits values use #a IF a < 0 THEN PRINT "-"<2>,-a ELSE PRINT <3>-a Learn kids, don't write code when you don't have 100% your attention on it Edit: I've edited the post, thanks Joe! 1 Quote Link to comment Share on other sites More sharing options...
intvnut Posted May 8, 2018 Share Posted May 8, 2018 Learn kids, don't write code when you don't have 100% your attention on it Edit: I've edited the post, thanks Joe! Indeed. I was guilty of that the other day in the random-position-in-a-square thread, where I wrote 14 (the correct value), edited it to 19 (incorrect) and then had to wipe the egg off my face while changing it back to 14. *d'oh* 2 Quote Link to comment Share on other sites More sharing options...
carlsson Posted May 8, 2018 Share Posted May 8, 2018 I thought Nanochess did that mistake on purpose, as an exercise to the reader (mainly First Spear). I was about to comment about it, but I wasn't sure if I was missing out on some smart detail so I didn't. Yes, it has reached that point that when Nanochess posts code snippets, I'm more willing to think he has come up with something spectacularly clever than having made a typo... The same goes for Intvnut and some others. 3 Quote Link to comment Share on other sites More sharing options...
+nanochess Posted May 8, 2018 Share Posted May 8, 2018 I thought Nanochess did that mistake on purpose, as an exercise to the reader (mainly First Spear). I was about to comment about it, but I wasn't sure if I was missing out on some smart detail so I didn't. Yes, it has reached that point that when Nanochess posts code snippets, I'm more willing to think he has come up with something spectacularly clever than having made a typo... The same goes for Intvnut and some others. Well, there are days when I'm not so smart 2 Quote Link to comment Share on other sites More sharing options...
intvnut Posted May 9, 2018 Share Posted May 9, 2018 Well, there are days when I'm not so smart Ditto! 1 Quote Link to comment Share on other sites More sharing options...
Kiwi Posted May 15, 2018 Share Posted May 15, 2018 And there are times that I used AND instead of OR for Towering Inferno to get that enemy to work properly. Good times. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.