Another LOG question

So, I'm building a light function using a logarithmic function, in this case a LOG15, In excel it gives me exactly what I need, a value from 0 to 255 based on an input of 1000 to 1.

So I could use a

function baselog(x, y) {
     return Math.log(y) / Math.log(x);
    }
newMsg = baselog(1000, 15);
return newMsg;

but that returns an error.

Never mind, fixed it.....

function baselog(x, y) {
  return Math.log(y) / Math.log(x);
} 

msg.payload[2] = baselog(msg.payload[1], msg.payload[0]);
return msg;

It returns an error because a function node must return an object, also, I think you have x and y the wrong way round. Try this in a function node

// returns payload with log base 15 of incoming payload
msg.payload = baseLog(msg.payload, 15)
return msg;

// returns log of x base y
function baseLog(x, y) {
    return Math.log(x) / Math.log(y);
}

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.