on4bhm
1
Hi,
I have the following code:
(I want to convert dB’s into watt)
double CalculateWatt(float db)
{
double res = 0;
res = pow(10,db);
return res;
}
this function always return 0 !
this doesn’t seem normal to me.
I already included math.h
what else can I do?
on4bhm
2
changed it into:
double CalculateWatt(float db)
{
double res = 0;
res = pow(10,(db/10))/1000;
return res;
}
now it is working…
had propably an overflow…
What values were you passing as db
?
With this code I can’t reproduce your issue trying 0.1, 1.2, 12.3 and even 123.456.
1234.56 returns inf
but not 0.
#include <math.h>
double CalculateWatt(float db)
{
double res = 0.0;
res = pow(10, db);
return res;
}
void setup() {
Particle.function("set", set);
}
int set(const char* cmd) {
double x = atof(cmd);
Serial.printlnf("%f", CalculateWatt(x));
return x;
}
2 Likes