Unexpected log10 results

The log10 function in math.h is behaving differently from what I expected.
My understanding is that log10(10000) will produce a result of 4 but I get 2.0553e-320

This is my code:

#include <math.h>

double result = 0;

void setup()
{
  Spark.variable("result", &result, DOUBLE);
}

void loop()
{
  result = log10(10000);
  delay(500);
}

Why I am not getting 4 as answer?

HI @philipf

I don’t think doubles as :spark: variables are working yet. Try a string:

#include <math.h>

double result = 0;
char resultstr[64];

void setup()
{
  Spark.variable("result", &resultstr, STRING);
}

void loop()
{
  result = log10(10000);
  sprintf(resultstr, "%f",result);
  delay(5000);
}

This code worked for me!

2 Likes

I had problems with DOUBLE and FLOAT in Spark.variable. At this time, neither of these is working (only INT and STRING seem to work). I ended up using a float (or double) for the calculations but using a Spark.variable of type STRING. Then I converted the float to a STRING using sprintf(). It’s ugly but until they fix the cloud API, it’s the only way it works.

:frowning:

2 Likes

Hi guys, thank you for taking time to explain this issue to me.
It is working as expected now as per @bko’s example

1 Like