Page 1 of 1

Operator **

Posted: Tue May 22, 2007 11:47 am
by Leonhard
I need this Operator!

Example:

Code: Select all

Debug 3**4 ;/ Returns 3^4 = Pow(3, 4) = 81
Debug 2**(1/2) ;/ Returns 2^(1/2) = Pow(2, 1/2) = 1,414213...

Posted: Tue May 22, 2007 12:05 pm
by Derek
But you just showed yourself how to use the pow() command, why do you need ** ?

Posted: Tue May 22, 2007 1:55 pm
by Psychophanta
For jokes please go to offtopic area :lol:

Posted: Tue May 22, 2007 4:57 pm
by AND51
Three Reasons that support this request:
1) It's much more comfortable to use.
2) It looks more cool. :wink:
3) This would also work correctly with Longs (however, Pow accepts Float only).

For the case, that this will be inplemented, please don't use **. In my opinion ^ is better.

Posted: Tue May 22, 2007 5:14 pm
by Chrono Syndrome
Well, I support zis idea too.

Posted: Tue May 22, 2007 5:28 pm
by Deeem2031

Code: Select all

Global x, a, *a

x*a
x**a ;(x^a) or (x * *a) ?
x***a
"**" is no good idea ;)

Posted: Tue May 22, 2007 5:40 pm
by AND51
That's why I prefer ^

Posted: Tue May 22, 2007 6:26 pm
by Flype
about ^, yes as many other languages.

but the rules about types conversion should be clearly described before.

type? = var_long ^ var_long
type? = var_long ^ var_float
type? = var_long ^ var_double
...

type? = var_float ^ var_long
type? = var_float ^ var_float
type? = var_float ^ var_double
...

and so on...

Posted: Tue May 22, 2007 6:27 pm
by Psychophanta
AND51 wrote:That's why I prefer ^
That's why i told '**' was a joke. 8)

And it was already requested:
http://www.purebasic.fr/english/viewtopic.php?t=7730

So then this thread seems a double joke.

Posted: Tue May 22, 2007 6:46 pm
by Trond
Flype wrote:about ^, yes as many other languages.

but the rules about types conversion should be clearly described before.

type? = var_long ^ var_long
type? = var_long ^ var_float
type? = var_long ^ var_double
...

type? = var_float ^ var_long
type? = var_float ^ var_float
type? = var_float ^ var_double
...

and so on...
long ^ long -> long
long ^ float -> float
long ^ double -> double
float ^ long -> float
float ^ float -> float
float ^ double -> double
double ^ * -> double
quad ^ long -> quad
long ^ quad -> quad
quad ^ double -> double
double ^ quad -> double
quad ^ float -> float
float ^ quad -> float

Posted: Wed May 23, 2007 10:32 am
by Derek
Using ^ would be ok.
Trond wrote: long ^ long -> long
long ^ float -> float
long ^ double -> double
float ^ long -> float
float ^ float -> float
float ^ double -> double
double ^ * -> double
quad ^ long -> quad
long ^ quad -> quad
quad ^ double -> double =quad
double ^ quad -> double =quad
quad ^ float -> float =quad
float ^ quad -> float =quad
I would of thought that if either argument was a quad then the answer should be quad, same with doubles etc

Posted: Wed May 23, 2007 10:41 am
by thefool
Derek wrote:Using ^ would be ok.
Trond wrote: long ^ long -> long
long ^ float -> float
long ^ double -> double
float ^ long -> float
float ^ float -> float
float ^ double -> double
double ^ * -> double
quad ^ long -> quad
long ^ quad -> quad
quad ^ double -> double =quad
double ^ quad -> double =quad
quad ^ float -> float =quad
float ^ quad -> float =quad
I would of thought that if either argument was a quad then the answer should be quad, same with doubles etc
no. Quads do not support decimals while doubles do, hence result has to be a double.

Posted: Wed May 23, 2007 10:58 am
by Derek
I just assumed that if you were using quads then you would be going for a higher number rather than a more accurate number including decimals but I guess it could be argued both ways.

Posted: Wed May 23, 2007 11:20 am
by thefool
Derek wrote:I just assumed that if you were using quads then you would be going for a higher number rather than a more accurate number including decimals but I guess it could be argued both ways.
:)

Posted: Wed May 23, 2007 12:13 pm
by Kaeru Gaman
I second the request for ^ as "to the power of"

and I also request an optimized implementation.

if I use only integers and get an integer result, the returned type should be integer, too,
not forced float like the Pow()-Function returns.

additionally, it would be really great if it would be translated into a bitshift (in the asm-code) if the base is a power of two.