Can't get log() to give expected results

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cdoyle
Forum Contributor
Posts: 102
Joined: Wed Feb 13, 2008 7:26 pm

Can't get log() to give expected results

Post by cdoyle »

In my game, I'm trying to create a way for my players to add audio equipment to their vehicles, and to compete in sound offs. So I'm trying to make it a little realistic and I looked up a SPL calculator online, and trying to mimic what they did.

I found this one
http://myhometheater.homestead.com/splcalculator.html

so I downloaded the excel version, and looking at the formulas.
This is where I'm getting stuck.

Under Power if you put 1000 in the next column it calculates the db value using this formula.
=10*LOG(Power)
the result 30

So now in PHP I tried to do the same thing.

for testing I hardcoded the values

$power = 1000;
$db1 = 10*log($power);

but when I echo the result I get
169.0775527898???

I also looked at the comments here
http://us2.php.net/log

and tried
$db1 = 10*floor(log10($power));
$db1 = 10 * log($power, 10);
and
$db1 = 10 * log10($power);
these give me a result of 130?

what do I need to do, to get the same outcome as the example?
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Can't get log() to give expected results

Post by Darhazer »

Code: Select all

$power = 1000;
$db1 = 10 * log($power, 10);
echo $db1;
 
Gives exactly 30.
Post Reply