Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 04:43 28 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : True/False conflict using INV?

Author Message
PhenixRising
Senior Member

Joined: 07/11/2023
Location: United Kingdom
Posts: 284
Posted: 09:19am 11 Mar 2024
Copy link to clipboard 
Print this post

Manual:

  Quote  
The other logical operations result in the integer 0 (zero) for false and 1 for true


But:

Print inv 1


The result is -2


Print inv -1


The result is 0
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3841
Posted: 09:31am 11 Mar 2024
Copy link to clipboard 
Print this post

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
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
PhenixRising
Senior Member

Joined: 07/11/2023
Location: United Kingdom
Posts: 284
Posted: 09:54am 11 Mar 2024
Copy link to clipboard 
Print this post

  thwill said  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


Thanks Tom. I do use NOT but I tested INV without consulting the manual  
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2289
Posted: 10:24am 11 Mar 2024
Copy link to clipboard 
Print this post

from page 27 of the User Manual, MMBasic Ver 5.08.00, Revision 4:

  Quote  NOT INV
invert the logical value on the right (e.g. NOT a=b is a<>b) or bitwise inversion of the value on the right (e.g. a = INV b)


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 Kingdom
Posts: 3659
Posted: 10:50am 11 Mar 2024
Copy link to clipboard 
Print this post

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 Zealand
Posts: 2289
Posted: 11:06am 11 Mar 2024
Copy link to clipboard 
Print this post

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: Germany
Posts: 1133
Posted: 11:28am 11 Mar 2024
Copy link to clipboard 
Print this post

  robert.rozee said  ... 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. [...]

I don't see the problem.
The MMbasic manual says on page 45:
  Quote  ... For normal use of NOT or INV the expression to be operated on should be placed in brackets. Eg:
IF NOT (A = 3 OR A = 8) THEN ...

Regards
Michael
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 01:04pm 11 Mar 2024
Copy link to clipboard 
Print this post

  robert.rozee said  the above example from the user manual "NOT a=b is a<>b" is wrong

Well spotted, thanks Rob.

  robert.rozee said  unary operators ... should always have their parameter enclosed in brackets to prevent confusion!

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.

  robert.rozee said  should it be legal to have a variable with the same name as a function?

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 Kingdom
Posts: 1643
Posted: 02:00pm 11 Mar 2024
Copy link to clipboard 
Print this post

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
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024