Operator **

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Leonhard
User
User
Posts: 55
Joined: Fri Jun 16, 2006 7:43 am

Operator **

Post 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...
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

But you just showed yourself how to use the pow() command, why do you need ** ?
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

For jokes please go to offtopic area :lol:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post 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.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
Chrono Syndrome
Enthusiast
Enthusiast
Posts: 169
Joined: Thu Oct 05, 2006 6:44 am
Contact:

Post by Chrono Syndrome »

Well, I support zis idea too.
Don't try to catch ze Night !
Remember: 'z' is better zen 'th' =) !
Sorry for bad english.
User avatar
Deeem2031
Enthusiast
Enthusiast
Posts: 216
Joined: Sat Sep 20, 2003 3:57 pm
Location: Germany
Contact:

Post by Deeem2031 »

Code: Select all

Global x, a, *a

x*a
x**a ;(x^a) or (x * *a) ?
x***a
"**" is no good idea ;)
irc://irc.freenode.org/#purebasic
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

That's why I prefer ^
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post 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...
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post 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
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post 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.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post 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.
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post 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.
:)
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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.
oh... and have a nice day.
Post Reply