Author Topic: Request: MOD as an operator  (Read 1643 times)

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

  • Guest
Request: MOD as an operator
« on: May 20, 2019, 01:27:21 PM »

 Having mod function is fine, but how about adding it as an operator? :)

Charles Pegge

  • Guest
Re: Request: MOD as an operator
« Reply #1 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


Brian Alvarez

  • Guest
Re: Request: MOD as an operator
« Reply #2 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...

Arnold

  • Guest
Re: Request: MOD as an operator
« Reply #3 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

Charles Pegge

  • Guest
Re: Request: MOD as an operator
« Reply #4 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.


Brian Alvarez

  • Guest
Re: Request: MOD as an operator
« Reply #5 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.

Charles Pegge

  • Guest
Re: Request: MOD as an operator
« Reply #6 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.

Brian Alvarez

  • Guest
Re: Request: MOD as an operator
« Reply #7 on: May 21, 2019, 10:17:34 AM »

No problem charles, I already implemented it here. :)

Mike Lobanovsky

  • Guest
Re: Request: MOD as an operator
« Reply #8 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. ;)

JRS

  • Guest
Re: Request: MOD as an operator
« Reply #9 on: May 23, 2019, 06:59:45 PM »
Is NOT a function or an operator in O2?

Brian Alvarez

  • Guest
Re: Request: MOD as an operator
« Reply #10 on: May 23, 2019, 08:00:11 PM »
Is NOT a function or an operator in O2?

A function.

Charles Pegge

  • Guest
Re: Request: MOD as an operator
« Reply #11 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
« Last Edit: May 23, 2019, 08:41:09 PM by Charles Pegge »