'pow' was not declared in this scope

I have purchased a GA1A12S202 Log-scale Analog Light Sensor from Adafruit and I am following the tutorial to get it setup, making modifications if required for the Spark Core.

The example contains the following function:

float RawToLux(int raw) {
    float logLux = raw * logRange / rawRange;
    return pow(10, logLux);
}

When using it I am am unable to compile due to the following error:

/nimbus.cpp:103:26: error: 'pow' was not declared in this scope

I was under the impression that the pow function is available as part of the Spark Core so I am a little confused as to why it is not working.

@scottsweb, you need to add #include <math.h> to your file. This is an odd one and we are working to get that included as part of “application.h”. :smile:

1 Like

Perfect. That has done the trick.

1 Like

Sorry for kicking this up, but I came across this error. Including #include <math.h> to my file works out fine. However almost 1,5 year later pow doesn’t seem to be part of “application.h”, so maybe you can still add it?

That sounds odd, but you can still add #include <math.h>
But I might file a PR right now :wink: - or not @mdma :sunglasses:

Is it included by default in Arduino? I’m really on the fence here about whether it should be included by default or not. We don’t include a lot of other standard library headers by default, but equally I can see this might be useful.

The danger with including headers that weren’t included before is breaking existing libraries.

1 Like

@mdma, it is NOT included by default in Arduino! I would not change anything and keep it separate IMO. :wink:

2 Likes