Location: PHPKode > scripts > RCD Script > rcd-classes/RCD.php
<?
// Class: RCD
// By: Seb Renauld
// License: GNU

class RCD {
	function age($hlife,$pca) {
		// Returns the age from the half life
		// in years, and the percentage of
		// activity at the time (where the initial
		// activity is 100
		//
		// For example:
		// Carbon 14: half-life: 5568
		// pca: 95
		if ($pca <= 100) {
			$alpha = $hlife/log(2);
			$age = $alpha*log(100/$pca);
			$unit = "y";
			if ($age <= 1) {
				$age = $age*365;
				$unit = "d";
				if ($age <= 1) {
					$age = $age*24;
					$unit = "h";
					if ($age <= 1) {
						// Seconds are more precise :)
						$age = $age*3600;
						$unit = "s";
					}
				}
			}
			return round($age,2).$unit;
		}
	}
	function hlife($age,$curact) {
		// Finds the half-life of something
		// When the age and current activity is given.
		// Reverse of the first formula :)
		// Age in years, as ever
		if ($curact <= 100) {
			$alpha = log(100/$curact)/$age;
			$hlife = log(2)/$alpha;
			return $hlife."y";
		}
	}
	function activity($age,$hlife) {
		// Finds the current activity (in percent)
		// from the age and half-life. Same as ever ;)
		$alpha = $hlife/log(2);
		$activity = 100 / exp($age/$alpha);
		return $activity."%";
	}
}
?>
Return current item: RCD Script