Is there a logarithm function in Craft or Twig? I searched the Craft and Twig documentation, although I did not find any information about a logarithm function (http://php.net/manual/en/function.log.php ). I am trying to calculate the loan amortization formula below in Craft / Twig:

{% set payoffTime  = -(ln(1 - ((128000 * '.05') / 1260)) / ln(1 + '.05')) %}


The numbers will be replaced with field handles once I can get the 'ln' function working. I'm not even sure if the formula is 'exactly' the way it should be yet - just trying to find a way to get logarithms working in Craft, and then go from there with testing, etc. :)

To give some background on the goal of this: it will calculate the amount of time it will take to pay off an amoritized loan, (mortgage, etc) based on the amounts the user has already submitted (loan amount, interest rate, extra payments, etc.) Also, this can't be done in Javascript - it needs to be in Craft since it's calculated from user data.

Thank you in advance for any info you can give about the logarithm function in Craft / Twig.

Thanks!
The short answer is no... because Twig is a templating language, and Craft doesn't otherwise have a general need for a log type of function.

The longer answer is you can very easily build this yourself!


Grab the Business Logic Template.
Delete the services and controllers folders... you won't need them.
In the BusinessLogicVariable.php file, change exampleVariable to payoffTime. Whatever parameters you assign to this function will correspond to the parameters you'll use when calling this variable from Twig.
Set whatever logic you want within the function, and return the resulting value.
Enable the plugin from your Control Panel.
Call that variable from your Twig template!

{% set payoffTime = craft.businessLogic.payoffTime(foo, bar) %}





UPDATE

Here's an example based on the use case you outlined in the comments below...

Twig:

{% set payoffTime = craft.businessLogic.payoffTime(entry.loanAmount, entry.loanPayment) %}


PHP:

public function payoffTime($loanAmount, $loanPayment)


Alternatively, if you wanted to, you could even pass the whole entry object in as a single parameter, and just use its field values once you're on the PHP side of things...

Twig:

{% set payoffTime = craft.businessLogic.payoffTime(entry) %}


PHP:

public function payoffTime($entry)
{
    // $entry-&gt;loanAmount
    // $entry-&gt;loanPayment
}