GLBasic forum

Feature request => IDE/Syntax => Topic started by: Moebius on 2011-Jan-05

Title: Syntax Request - 'MUL', 'DIV' [CLOSED]
Post by: Moebius on 2011-Jan-05
EDIT:  Killed measly request...

EDIT:  Updated request:
Currently we have shorthand functions for various operations (e.g. INC, DEC, POW, MOD), but nothing for multiplying and dividing.  Could we have functions like 'MUL' and 'DIV' to complete the operator set?



The following operators are available in C++:
+=, -=, *=, /=, %=, >>=, <<=, &=, ^=, |=

Could they be allowed through by GPC?  They can be useful in code, and are supported natively in C++, so from what I know the precompiler won't have to do any conversion.

Anyway, could these be 'included' in the allowed syntax?
Thanks.
Title: Re: Syntax Request - Allow '+=', '-=', etc.
Post by: Schranz0r on 2011-Jan-05
not basic-like!
Title: Re: Syntax Request - Allow '+=', '-=', etc.
Post by: Moebius on 2011-Jan-05
I know, but it would still be nice to have at least '*=' and '/=' like there is INC and DEC...  Admittedly the others are more complicated and unneeded...
...so with that in mind actually can I update my request?  Perhaps we could have some three letter functions like INC and DEC for multiplying and dividing?  MUL and DIV maybe?
Title: Re: Syntax Request - Allow '+=', '-=', etc.
Post by: hardyx on 2011-Jan-05
GLB supports this sentences. I think *= or <<= is more C-like than BASIC.
Code (glbasic) Select

INC var, 2      // var += 2
DEC var, 2      // var -= 2
INC var         // var++
DEC var         // var--

var = ASL(var, 2)    // var <<= 2
var = ASR(var, 2)    // var >>= 2


You can use too:

Code (glbasic) Select
INLINE
   var *= 2;
ENDINLINE

Title: Re: Syntax Request - Allow '+=', '-=', etc.
Post by: Moebius on 2011-Jan-06
I know, but it's still missing short multiply and divide functions.  It would be nice to have the same shorthand method for all different common operations.
We have INC, DEC, MOD, bAND bOR etc., ASL, ASR, and POW but no MUL and DIV...

QuoteI think *= or <<= is more C-like than BASIC
I see the point and I agree  :giveup:.  Updating my request (as I did in the second post...  :rtfm:), as we have commands for every single one of the 'something=' ops. except '*=' and '/=' it would nice to include something like 'MUL' and 'DIV'.
Title: Re: Syntax Request - 'MUL', 'DIV'
Post by: MrTAToad on 2011-Jan-08
Using MUL and DIV would offer no advantage (typing or execution optimisation) over using things like a%=a%*4
Title: Re: Syntax Request - 'MUL', 'DIV'
Post by: Moebius on 2011-Jan-08
What about "NewParticle.alpha = NewParticle.alpha * 0.8"?  :S
I know it's a measly request, but it would be nice to complete the set of functions...
Title: Re: Syntax Request - 'MUL', 'DIV'
Post by: Schranz0r on 2011-Jan-09
BING!
Title: Re: Syntax Request - 'MUL', 'DIV' [CLOSED]
Post by: Kitty Hello on 2011-Jan-10
I'll add it though, it's easy to do.