LOG in JS

Description

Returns the logarithm using the Euler's number as a base. (JavaScript LOG function Documentation).

Unfortunately, JavaScript does not provide a method that receives a logarithm base through its parameters, but this can be solved by dividing the base by the argument.

Sample Source Pattern

Syntax

Math.log( expression )

Arguments

expression: Numeric expression. It must be positive, otherwise returns NaN.

Return Type

Same data type sent through parameter as a numeric expression.

Examples

CREATE OR REPLACE FUNCTION base_log(base float, exp float)
  RETURNS float
  LANGUAGE JAVASCRIPT
AS
$$
  function getBaseLog(x, y){
    return Math.log(y)/Math.log(x);
  }
  return getBaseLog(EXP, BASE)
$$
;
SELECT BASE_LOG(2, 8);

Last updated