Pow '^' operator
Pow '^' operator
is there any hope to replace Pow(5,11) with 5^11 ?? at least using external substitution program
in fact i sometimes stumbled over situations like this:
y = (0.4^2-(0.6-(x^2+y^2)^0.5)^2)^0.5
such as the torus function:
http://www.benjoffe.com/code/tools/functions3d/examples
i feel tired when trying to replace the ^ with Pow or Sqr, it will be very complex most of the time since '^' are essential and recur too much in all literature, the '^' is available in quickbasic and all other basics and even in http://www.wolframalpha.com/ try Pow[2,3] it will give you 8, try again with 2^3 and the result is also 8
in Python we have **, ...
in perl try: print 2**3; and the result is 8
the Pow is a C specific
in fact i sometimes stumbled over situations like this:
y = (0.4^2-(0.6-(x^2+y^2)^0.5)^2)^0.5
such as the torus function:
http://www.benjoffe.com/code/tools/functions3d/examples
i feel tired when trying to replace the ^ with Pow or Sqr, it will be very complex most of the time since '^' are essential and recur too much in all literature, the '^' is available in quickbasic and all other basics and even in http://www.wolframalpha.com/ try Pow[2,3] it will give you 8, try again with 2^3 and the result is also 8
in Python we have **, ...
in perl try: print 2**3; and the result is 8
the Pow is a C specific
Re: Pow '^' operator
Hi applePi. What you need could only be achieved through the implementation of a new operator, and I believe that this can only be done by the dev team. However, you could look into creating a math parser and evaluator, which would take an entire expression, parse and calculate it, and return the results. The syntax would look something like this:applePi wrote:is there any hope to replace Pow(5,11) with 5^11 ??
Code: Select all
y = math("(0.4^2-(0.6-(x^2+y^2)^0.5)^2)^0.5") ;assuming the variables are globals
Just a suggestion.

Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel 

Re: Pow '^' operator
No need to reinvent the wheel: http://www.purebasic.fr/english/viewtop ... 12&t=15762TI-994A wrote:you could look into creating a math parser and evaluator
Re: Pow '^' operator
Well, there you go. Seems to work pretty well too.Dude wrote:No need to reinvent the wheel: http://www.purebasic.fr/english/viewtop ... 12&t=15762

Thanks Dude!
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel 

Re: Pow '^' operator
Thanks for the suggestions, i also have found a solution, is to use http://sourceforge.net/projects/bcx-basic/ . and after the install, make a test.bas file contains as an example y = (0.4^2-(0.6-(x^2+y^2)^0.5)^2)^0.5 then save it to its Bin folder and from command prompt write bc test.bas , it will produce test.c which is
y=pow((pow(.4,2)-pow((.6-pow((pow(x,2)+pow(y,2)),.5)),2)),.5);
then we use it in purebasic after replacing .5 to 0.5
seems usable
y=pow((pow(.4,2)-pow((.6-pow((pow(x,2)+pow(y,2)),.5)),2)),.5);
then we use it in purebasic after replacing .5 to 0.5
seems usable
Re: Pow '^' operator
Expression Parser by Danilo...
http://www.purebasic.fr/english/viewtop ... 33#p362333
http://www.purebasic.fr/english/viewtop ... 33#p362333
- It was too lonely at the top.
System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
Re: Pow '^' operator
Why on earth would you use a third-party solution when you can do it natively with PureBasic, as BlueB and I showed?applePi wrote:from command prompt write bc test.bas
Re: Pow '^' operator
applePi did ask for a expression converter that turnsDude wrote:Why on earth would you use a third-party solution when you can do it natively with PureBasic, as BlueB and I showed?applePi wrote:from command prompt write bc test.bas
Code: Select all
y = (0.4^2-(0.6-(x^2+y^2)^0.5)^2)^0.5
Code: Select all
y = pow((pow(0.4,2)-pow((0.6-pow((pow(x,2)+pow(y,2)),0.5)),2)),0.5)
Re: Pow '^' operator
Yes, he asked for a converter, which was the PureBasic code we linked to. It does the job, but he's going to use a non-PureBasic third-party solution instead to get the same results? I think it's better to keep it all as one single source code with one executable, rather than calling an external app to get the results. Just my 2 cents, anyway.
Re: Pow '^' operator
i seek the easy things Dude, i don't want to use converters/parsers which will complicate things.
i don't want to know what is the parser is. no time, too much reading .
and regarding the basic to C, i never used it until yesterday as if the collective global mind helps somehow. googling for basic to C translator he gives me BaCon: http://www.basic-converter.org but it is for Unix
the second result is BCX Basic to C translator, so looking inside bin i found BC.exe so i supposed it is basic to C and it is done easily. the meaning is that '^' are too natural and available in all documentation and not Pow which are used in c/c++ which are the programming languages in which the programmers make Higher level Languages which usually does not have Pow except wolframalpha which allow Pow or '^'. now since i have found the easy to use bc.exe there will be no problem when confronting a maze like '^' expression with many parenthesis. it is not bad to use easy to use basic to C translator to serve purebasic as a utility. using parsers makes the whole program complex and big but if that parser is inside the PB.exe/ pb.dll no problem.
i respect the developers choice anyway.
i don't want to know what is the parser is. no time, too much reading .
and regarding the basic to C, i never used it until yesterday as if the collective global mind helps somehow. googling for basic to C translator he gives me BaCon: http://www.basic-converter.org but it is for Unix
the second result is BCX Basic to C translator, so looking inside bin i found BC.exe so i supposed it is basic to C and it is done easily. the meaning is that '^' are too natural and available in all documentation and not Pow which are used in c/c++ which are the programming languages in which the programmers make Higher level Languages which usually does not have Pow except wolframalpha which allow Pow or '^'. now since i have found the easy to use bc.exe there will be no problem when confronting a maze like '^' expression with many parenthesis. it is not bad to use easy to use basic to C translator to serve purebasic as a utility. using parsers makes the whole program complex and big but if that parser is inside the PB.exe/ pb.dll no problem.
i respect the developers choice anyway.
Re: Pow '^' operator
+1 for the feature request of adding a power operator such as "**" or "^".
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
-
- Addict
- Posts: 4777
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Pow '^' operator
I'm neither for this request nor against it, but I've got an associated request:c4s wrote:+1 for the feature request of adding a power operator such as "**" or "^".
If such an operater will be implemented in PB, then it should work mathematically correct!

Unfortunately, I've often seen in expression evaluators that something like
4^3^2 is evaluated from left to right, which is mathematically wrong:
(4^3)^2 = 64^2 = 4096
Correctly, multiple power operators without any brackets are evaluated from right to left:
4^3^2 = 4^(3^2) = 4^9 = 262144
Re: Pow '^' operator
Thanks Little John for the notes, the bc.exe have translated:
a=4^3^2 wrongly to:
a=pow(pow(4,3),2);
while translated
a=4^(3^2) correctly to:
a=pow(4,(pow(3,2)));
but wolframalpha have deciphered 4^3^2 like you said from right to left with the result 262144, he positions 3 over 4 and 2 over 3

a=4^3^2 wrongly to:
a=pow(pow(4,3),2);
while translated
a=4^(3^2) correctly to:
a=pow(4,(pow(3,2)));
but wolframalpha have deciphered 4^3^2 like you said from right to left with the result 262144, he positions 3 over 4 and 2 over 3

Re: Pow '^' operator
I am not sure about that
Mathematica 4^3^2 -> 262144
Maple 4^3^2 -> Error, power is non-associative
Wikipedia says the exponential operator is right associative http://en.wikipedia.org/wiki/Operator_associativity
Maxima 4^3^2 -> 262144
Axiom 4^3^2 -> 262144
Reduce 4^3^2 -> 4096
so who's right?
Mathematica 4^3^2 -> 262144
Maple 4^3^2 -> Error, power is non-associative
Wikipedia says the exponential operator is right associative http://en.wikipedia.org/wiki/Operator_associativity
Maxima 4^3^2 -> 262144
Axiom 4^3^2 -> 262144
Reduce 4^3^2 -> 4096
so who's right?
Re: Pow '^' operator
vb6 wrote:debug.Print 4^3^2
4096
vs2013 wrote:3^3^3 = 19683
Last edited by skywalk on Mon Apr 20, 2015 7:38 pm, edited 1 time in total.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum