Oxygen Basic
Programming => Bugs & Feature Requests => Topic started by: Brian Alvarez on May 20, 2019, 01:27:21 PM
-
Having mod function is fine, but how about adding it as an operator? :)
-
Yes, we have it. (^ is not the bitwise xor C-operator)
print 2^3
float a,b
a=2
b=3
print a^b
print 2^0.5
-
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...
-
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
-
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.
-
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.
-
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.
-
No problem charles, I already implemented it here. :)
-
value MOD value
is canonical in BASIC while mod() isn't. Although I acknowledge it is easier implementable as a function than an operator. ;)
-
Is NOT a function or an operator in O2?
-
Is NOT a function or an operator in O2?
A function.
-
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