Mathf.Log10 Help

Discussion in 'Scripting' started by pdm, Jan 26, 2018.

1. pdm

Joined:
Dec 31, 2015
Posts:
3
Hi All,

I can normally find answers to my questions but seem to be stumped on this so I need to put this to the Pros!

Ok so in Excel I have this formula ="ROUND(10*LOG10(10^((C6-26)/10)".

In C# I have something like this: sum = 10 * (Mathf.Log10(DB1-26)/10)

My question is how do I do a Mathf.Log10(10); in a sum?
I get an error if I do sum = 10 * (Mathf.Log10(10(DB1-26)/10)) or sum = 10 * (Mathf.Log10(10)(DB1-26)/10)

Background on the app:
Sound spectrum, 63hz, 125hz, 250hz, etc upto 8K.
User inputs their dB details in the input fields (DB1, DB2, DB3 etc)
Result I need is dB(A) at a distance (meters) the user inputs into another input field.

Many Thanks

Tony.

2. BubyMB

Joined:
Jun 6, 2016
Posts:
140
in the equation '10 * (Mathf.Log10(10)(DB1-26)/10)' between Mathf.Log10(10) and (DB1-26) I am assuming you are trying to multiply, add '*' inbetween, also can you show us the error?

3. pdm

Joined:
Dec 31, 2015
Posts:
3
Yeah no problem, not at my home computer at moment, will post the error tonight.
Will try the * as mentioned.

Thank you for getting back to me so quick.

4. DonLoquacious

Joined:
Feb 24, 2013
Posts:
1,655
^ in Excel is "raise to this power of". In C# this would probably look something like:
Code (CSharp):
1. Mathf.RoundToInt(10 * (Mathf.Log10(Mathf.Pow(10, (DB1 - 26) / 10))))

Joined:
Dec 31, 2015
Posts:
3