Android Question How do I use exponential math?

Levisvv

Member
Licensed User
Longtime User
I need to calculate a ratio that uses a bit of complex math.

I have a number that I need to equate to its exponent of 6 or 7, how do I do this in B4A?

example I expect 4^5 to be the same as 4*4*4*4*4
but the ^ gives me an error.

How can I used exponential math?
 

stevel05

Expert
Licensed User
Longtime User
Use the Power Function:

B4X:
Power (Base As Double, Exponent As Double) As Double
'Returns the Base value raised to the Exponent power.
 
Upvote 0

Levisvv

Member
Licensed User
Longtime User
The following is giving me an error:
B4X:
Dim FLrate As Double
Dim DRVqty As Int
DRVqty=4
Dim Frate As Double
Frate=.0035

FLrate= 1 - ((1-Frate) ^ DRVqty)
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
The ^ is not a valid operator, you need to use the power function.

Try Using:

FLrate= 1 - Power(1-Frate, DRVqty)
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
The problem is not number "3", the problem is that you are using double numbers
Try:
B4X:
Dim p3 = 3 As Int
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
Yes, you are right, but it's the same.
The problem is that the parameters of Power function is double type, so the system convert p3 from Int to Double type, and we know that double type has a precision problem because it isn't bit-bit (like an Int) but is representive by mantissa and exponent, so you can have a precision problem (like, for example numer 3).

Sergio
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…