lime icon

Phosphorus and Lime

A Developer's Broadsheet

This blog has been deprecated. Please visit my new blog at
PHP: Create Your Own Richter Scale
This formula provides a way to take any set of somewhat arbitrary data and put it on a scale of your choosing. I used it specifically for frequency values in a wordlist I had, but it has a variety of applications.

The key to this formula is the conversion of bases, using this formula:

exp = log(result) / log(base)

Here's the code (values are configurable):

// 100 pt logarithmic scale
$max_raw_value = 18349;
$scale_max = 100;

$scaled_value = round( log($raw_value)/log(pow($max_raw_value,1/$scale_max)) );

Note that a $raw_value of 1 will equal 0, which wasn't valid for my use. So I converted raw values of 1 to 1.1, which resulted in a scaled value of 1.

I might also note that this lead me to my first practical application of logarithms. (I just wish my calculus teacher in high school would have offered a practical example like this.)