Logarithm calculation


How may I do a logarithm math calculation on Xano. For example: Ln(variable1) / Ln(variable2).

I understand there is Lambda but I need to upgrade for that which I can't do now. I also found this : https://api.mathjs.org/ but I need to call an external API. Before trying this, I would like to know whether Xano allows me to do such math first?

Thank you

Best Answers


  • arturosanz
    arturosanz Member ✭✭

    It's strange that Xano has the exp math filter but not the inverse, the log filter yet.

    Calling a external API to do this seems like using a sledgehammer to crack a nut.

    Here is another suggestion for you.

    Create the following custom function and call it log.

    Example to calculate log(25):
    1) Divide 25 by the nearest power of 10. The condition must be 25 ≥ 10n.
    2) The value of n is 1 because 25 ≥ 101. So the initial answer is 1.xxxxxx.
    3) Divide 25 by 101. The result is 2.5.
    4) Raise 2.5 by 10. So 2.510 ≈ 9536.7
    (Note: The number is raised to 10 because we are already looking for the digits after the decimal point.)
    5) For the next values, the same process will be used.
    6) Divide 9536.7 by the nearest power of 10.
    7) 9536.7 ≥ 103 so n=3. The answer is now 1.3xxxxx.
    8) 9536.7 / 103 = 9.5367
    9) Raise 9.5367 to 10. 9.536710 = 6222733625
    10) 6222733625 ≥ 10n so n=9. The answer is now 1.39xxxx.
    11) Repeat the same process until you get the desired precision.
    12) So log (25) ≈ 1.39794.

    This also works on logs with bases other than 10, even with decimals. In solving loga(x), just replace 10n with an. Also in solving for n, simply just divide the number by the base repeatedly until you get a quotient nearest to 1. The number of times you divided is n. (ie. 250/10= 25 (1), 25/10=2.5 (2), so n=2)

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭

    Arturo's trick is good. I would use a lambda to do the calculation, where the built-in JS math operators are all available. Like:

    return Math.log($var.variable1). / Math.log($var.variable2)

    (Without a second argument, Math.log defaults to euler's number as the base, making a natural log)

  • arturosanz
    arturosanz Member ✭✭

    @Mr Unfreeze

    🤗 Want to submit a feature request? Click here.