|
Forum Index : Microcontroller and PC projects : True/False conflict using INV?
| Author | Message | ||||
| PhenixRising Guru Joined: 07/11/2023 Location: United KingdomPosts: 2076 |
Manual: But: Print inv 1 The result is -2 Print inv -1 The result is 0 |
||||
| thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 4395 |
I'm braced to be told that I am talking out of my arse but INV isn't a logical operation (you might be looking for NOT), it's a bit operation. > ? Bin$(1, 64) 0000000000000000000000000000000000000000000000000000000000000001 > ? &b1111111111111111111111111111111111111111111111111111111111111110 -2 > ? Bin$(-1, 64) 1111111111111111111111111111111111111111111111111111111111111111 > ? &b0000000000000000000000000000000000000000000000000000000000000000 0 Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
| PhenixRising Guru Joined: 07/11/2023 Location: United KingdomPosts: 2076 |
Thanks Tom. I do use NOT but I tested INV without consulting the manual |
||||
| robert.rozee Guru Joined: 31/12/2012 Location: New ZealandPosts: 2552 |
from page 27 of the User Manual, MMBasic Ver 5.08.00, Revision 4: what is interesting is that the above example from the user manual "NOT a=b is a<>b" is wrong: > > a=5 > b=6 > ? a<>b 1 > ? not a=b ' interpreted as (not a)=b 0 > ? not (a=b) ' interpreted correctly with brackets 1 > the priority of both NOT and INV are higher than that of = and <>. this is a good example of why unary operators (which are really just a sub-class of functions) should always have their parameter enclosed in brackets to prevent confusion! now, as for functions, they present an extra level of mayhem: > > sin=12 > ? sin 34 12 34 > ? sin(34) 0.5290826861 > clearly the mmbasic interpreter is expecting the function's parameter to be enclosed in brackets, but behaves badly if none are present. questions - should it be legal to have a variable with the same name as a function? should it be made mandatory to enclose the parameter lists for functions and unary operators in brackets? cheers, rob :-) |
||||
| JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 4378 |
If it's meant to be as if not (a=b) then the manual could do with a fix - good find if so. John |
||||
| robert.rozee Guru Joined: 31/12/2012 Location: New ZealandPosts: 2552 |
hi John, i think in the first instance it is an error in the manual, although one that illustrates a classic programming mistake. a further test: > > x=sin 34 Error: Expression syntax > > x=sin (34) > ? x 0.5290826861 > reveals brackets around function parameters are already mandatory, and that the error here is in allowing function names to be used as variable names. so something like ? sin should give a syntax error, as should sin=1. the question of how to handle unary operators remains open; i suspect the failure goes way back to when BASIC was first created some 60 years ago. personally, i'd like to see INV, NOT, and - (the last being negation) required to have mandatory brackets around the parameter. cheers, rob :-) Edited 2024-03-11 21:07 by robert.rozee |
||||
| twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1769 |
I don't see the problem. The MMbasic manual says on page 45: Regards Michael ‚My name is Ozymandias, king of kings Look on my works, ye Mighty, and despair!‘ Nothing beside remains. Round the decay Of that colossal wreck, boundless and bare The lone and ... |
||||
| Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3368 |
Well spotted, thanks Rob. NOT does not need to be followed by brackets (for example, NOT PIN(xx)) and Microsoft (in their wisdom) did not require brackets. I understand your point but doing ast you say would cause greater problems. It is not legal for variables to use a function name. The fault is that MMBasic does not have a sufficiently sophisticated error detecting mechanism to detect this... it just stumbles on as best as it can. Geoff Geoff Graham - http://geoffg.net |
||||
| stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2807 |
this toggles fno 1 or 0. inc fnc: if fnc=5 then fnc=0:fno=not fno 'in wisdom no endif needed if fno=0 then else Edited 2024-03-12 01:45 by stanleyella |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2026 |