Math functions Exp and Log

bobsimoneau

Member
Licensed User
Longtime User
I am trying to convert the below list vb.net code to b4a. I can not tell if I can use power and Logarithm in place of exp() and Log().

Public Function InvestFV(ByVal Principal As Double, ByVal InterestRate As Double, _
ByVal CompoundYear As Integer, ByVal NumberMonths As Integer) As Double
Dim Growth As Double
Growth = Exp(NumberMonths / 12.0# * CompoundYear * _
Log(1.0# + InterestRate / 100.0# / CompoundYear))
InvestFV = (Principal * Growth)
End Function
 

bobsimoneau

Member
Licensed User
Longtime User
I was pretty sure it was Power and Logarithm but:
In VB.NET it is Public Shared Function Exp (d As Double) As Double
Note the single parameter
Description: Returns e raised to the specified power.

In VB.NET it is Public Shared Function Log ( d As Double) As Double
Again note the single parameter
Description: Returns the natural (base e) logarithm of a specified number.

Basic4Android requires two parameters for each function. That is where I am lost.
 
Upvote 0

bobsimoneau

Member
Licensed User
Longtime User
I was pretty sure it was Power and Logarithm but:
In VB.NET it is Public Shared Function Exp (d As Double) As Double
Note the single parameter
Description: Returns e raised to the specified power.

In VB.NET it is Public Shared Function Log ( d As Double) As Double
Again note the single parameter
Description: Returns the natural (base e) logarithm of a specified number.

Basic4Android requires two parameters for each function. That is where I am lost.

I got it thanks, it is:

Sub InvestFV(Principal As Double, InterestRate As Double, CompoundYear As Int, NumberMonths As Int) As Double
Dim Growth As Double
Dim e As Double
e = 2.7182818284590452354
Growth = Power(e, NumberMonths / 12.0 * CompoundYear * Logarithm(1.0 + InterestRate / 100.0 / CompoundYear,e))
Return (Principal * Growth)
End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You don't need to define a variable for e , there does exist a constant cE
B4X:
Sub InvestFV(Principal As Double, InterestRate As Double, CompoundYear As Int, NumberMonths As Int) As Double
    Dim Growth As Double
 
    Growth = Power(cE, NumberMonths / 12.0 * CompoundYear * Logarithm(1.0 + InterestRate / 100.0 / CompoundYear,cE))
    Return (Principal * Growth)
End Sub
Best regards
 
Last edited:
Upvote 0

bobsimoneau

Member
Licensed User
Longtime User
You don't need to define a variable for e , there does exist a constant cE
B4X:
[FONT=Courier New]Sub InvestFV(Principal As Double, InterestRate As Double, CompoundYear As Int, NumberMonths As Int) As Double[/FONT]
[FONT=Courier New] Dim Growth As Double[/FONT]
 
[FONT=Courier New] Growth = Power(cE, NumberMonths / 12.0 * CompoundYear * Logarithm(1.0 + InterestRate / 100.0 / CompoundYear,cE))[/FONT]
[FONT=Courier New] Return (Principal * Growth)[/FONT]
[FONT=Courier New]End Sub[/FONT]

Best regards

Thank you, Sir
 
Upvote 0

John H. Guillory

Member
Licensed User
Longtime User
Upvote 0
Top