Oxygen Basic

Programming => Bugs & Feature Requests => Topic started by: Brian Alvarez on May 20, 2019, 01:27:21 PM

Title: Request: MOD as an operator
Post by: Brian Alvarez on May 20, 2019, 01:27:21 PM

 Having mod function is fine, but how about adding it as an operator? :)
Title: Re: Request: MOD as an operator
Post by: Charles Pegge on May 20, 2019, 02:13:00 PM
Yes, we have it. (^ is not the bitwise xor C-operator)

Code: [Select]
print 2^3
float a,b
a=2
b=3
print a^b
print 2^0.5

Title: Re: Request: MOD as an operator
Post by: Brian Alvarez on May 21, 2019, 12:29:30 AM
 I thought ^ was EXP....

https://www.oxygenbasic.org/o2manual1/exp.htm

 Then which one is exponentiation operator?

How about making the % symbol the MOD operator and the ^ symbol the EXP operator?
That is more standard...
Title: Re: Request: MOD as an operator
Post by: Arnold on May 21, 2019, 01:10:41 AM
Hi Brian,

checking the results of the examples provided by Charles I assume ^ is the exponential operator. The other possible way is using pow. What is wrong with mod(83.5,10)?

In Oxygenbasic % is reserved for constants, variation %%. I never had a problem to accept this. But I have a problem with the term standard. Standard of what language? C, Pascal, Ada, Python, Freebasic, PHP etc? Not all of them use % as a modulo operator.

Roland
Title: Re: Request: MOD as an operator
Post by: Charles Pegge on May 21, 2019, 01:39:55 AM
Sorry, my brain had already gone to bed! I was thinking of pow()

I think we have used up all the common symbols, and a mod function is easy enough to use in an expression. And there's no ambiguity - trying to figure out operator precedence.

Title: Re: Request: MOD as an operator
Post by: Brian Alvarez on May 21, 2019, 04:51:25 AM
I think we have used up all the common symbols...

Well, its up to you, but % is available. There is a clear difference between using it in the first place of a line (since constants do not require to use the % with the constant after the definition), than in using it in the middle of two keywords, or variables or whatever. Besides, there is always the good old mod reserved word if you like it more. :)

I have no problem implementing it in my side, but i rather not create a new flag variable in the tokenizer (i am using all 64 bits right now :D), as it increases the memory required during
compilations.
Title: Re: Request: MOD as an operator
Post by: Charles Pegge on May 21, 2019, 09:11:13 AM
I looked for mod() in the o2 file collection (about 1200 files), and found that it only occured in 25 files; about 2% usage. So I don't think it is worth an additional implementation as an operator.
Title: Re: Request: MOD as an operator
Post by: Brian Alvarez on May 21, 2019, 10:17:34 AM

No problem charles, I already implemented it here. :)
Title: Re: Request: MOD as an operator
Post by: Mike Lobanovsky on May 23, 2019, 10:20:46 AM
value MOD value

is canonical in BASIC while mod() isn't. Although I acknowledge it is easier implementable as a function than an operator. ;)
Title: Re: Request: MOD as an operator
Post by: JRS on May 23, 2019, 06:59:45 PM
Is NOT a function or an operator in O2?
Title: Re: Request: MOD as an operator
Post by: Brian Alvarez on May 23, 2019, 08:00:11 PM
Is NOT a function or an operator in O2?

A function.
Title: Re: Request: MOD as an operator
Post by: Charles Pegge on May 23, 2019, 08:30:36 PM
print hex not(1+2) 'FFFFFFFC


We also have a specialised logical not for use with conditionals:

if not a ...
if not a>b ...
while not f()
...


not is also used as an a assembly code instruction for bitwise inversion.

not rax