Reputation: 528
I am trying to do a math function in a function-block in Node-RED but it can only handle easier task like multiply.
I am trying to do this function but it can't handle the exponents(^). Perhaps there is a math function or something to declare this? It just returns a wacko number as it is now.
msg.payload = (6*10^47)/(msg.payload^16.66);
return msg;
Upvotes: 1
Views: 11223
Reputation: 2120
You can use the cmath header which contains the pow function, in your case it would look something like:
#include <cmath>
msg.payload = (6*std::pow(10,47))/(std::pow(msg.payload,16.66));
return msg;
The number returned is the first parameter raised by the second.
Upvotes: 3
Reputation: 36513
The ^
operator doesn't do what you think it does, it's the bitwise XOR operator.
If you want to raise something to the power of x use pow
:
#include <cmath>
std::pow(msg.payload, 16.66);
Upvotes: 2