 # logarithms with floats?

I would like to use logarithms with a program I am writing but I don't understand the correct syntax for logarithms. I can't really find it easily so I figured I'd ask here.

for what I'm trying to do I basically want

log(base10)t = x

If logarithms can't be done is there an alternative way to do this?

If logarithms can't be done

They can. What is the real problem?

I don't understand the syntax for logarithm, that's the issue. I don't know how to tell arduino to do logarithms with base 10.

The syntax for logarithm is a function call that passes a float, and returns a float.

obito94: If logarithms can't be done is there an alternative way to do this?

The AVR LIBC contains two functions for calculating logarithms: http://www.nongnu.org/avr-libc/user-manual/group__avr__math.html#ga7f7d556ab6b6235777a179647c152126

The log() functions calculates the 'natural logarithm' and the log10() function calculates the 'decimal logarithm'.

jremington: First hit on Google: http://www.techonthenet.com/c_language/standard_library_functions/math_h/log10.php

The thing I don't understand here is

``````double log10(double x);
``````

It seems that up here log10 is defined and uses "x" say for example I wanted to give "x" a value. If I do this then does that work?

``````double x=360;
double log10(x);
``````

If this is the case then what do I put for delay? I can't put "x" as "x" just equals 360

It seems that up here log10 is defined and uses "x"

Yes.

say for example I wanted to give "x" a value. If I do this then does that work?

No. That won't even compile.

``````  double x=360;
double val = log10(x);
``````

will compile. Whether val is even close to what you expect, or not, is anybody's guess.

I see your problem. You don’t understand parameter passing.

Forget about “x”. It’s a name that is internal to the function. It is outside the scope of the calling program (not visible to it). The value that you pass to log10() replaces x inside the function.

If you need the log of some number, say “ourNumber” and assign it to val, it would be like this:

``````val = log10(ourNumber);
``````