Exponents

Blitz3D Forums/Blitz3D Beginners Area/Exponents

Anarcade(Posted 2003) [#1]
What is the command for exponents. ie.How do I raise something to the nth power. I know in many languages it is ^^ but I cannot find reference to it. On the same topic can exponential notation be used.


soja(Posted 2003) [#2]
You can use ^.

e.g.: 2^4 = 16.0

Also, I suppose you could use exponential notation.

e.g. 2*10^6 = 2 million


jhocking(Posted 2003) [#3]
Does that work in Blitz code? I never knew that; never had to use any exponents before.


soja(Posted 2003) [#4]
Yep, those are Blitz operators, and they're resolved in the correct order. Go ahead and try it.


Oldefoxx(Posted 2003) [#5]
Note that ^ is a higher priority than most other operators, meaning that it will be performed before multiply, divide, add, subtract, and so on. If you want to raise a value to some complex power, such as a+1, you will have to enclose the a+1 in parentheses to ensure that it gets evaluated first like so: N=b^(a+1). By definition, any value to the power of 0 is equal to 1. That is, 1=0^0 would be true. However, any value to a power of 1 is itself: 0=0^1 would also be true. And negative powers are representations of reciprocals, such that 2^(-1) = 1/2.