LOG in JS
Last updated
Last updated
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.
Math.log( expression )
expression
: Numeric expression. It must be positive, otherwise returns NaN.
Same data type sent through parameter as a numeric expression.
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);