note 111235 added to book.math
| From: | HayleyWatson | Date: | Tue, 29 Jan 2013 19:48:02 +0000 |
| Subject: | note 111235 added to book.math | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-193426@lists.php.net to get a copy of this message | ||
Provides a function to rescale numbers so that the range [a,b] fits into the range [c,d].
<?php
function rescale($ab, $cd)
{
list($a, $b) = $ab;
list($c, $d) = $cd;
if($a == $b)
{
trigger_error("Invalid scale", E_USER_WARNING);
return false;
}
$o = ($b * $c - $a * $d) / ($b - $a);
$s = ($d - $c) / ($b - $a);
return function($x)use($o, $s)
{
return $s * $x + $o;
};
}
$fahr2celsius = rescale([32, 212], [0, 100]);
echo $fahr2celsius(98.6); // 37°C
?>
----
Server IP: 69.147.83.199
Probable Submitter: 122.57.198.66
----
Manual Page -- http://php.net/manual/en/book.math.php
Edit -- https://master.php.net/note/edit/111235
Del: integrated -- https://master.php.net/note/delete/111235/integrated
Del: useless -- https://master.php.net/note/delete/111235/useless
Del: bad code -- https://master.php.net/note/delete/111235/bad+code
Del: spam -- https://master.php.net/note/delete/111235/spam
Del: non-english -- https://master.php.net/note/delete/111235/non-english
Del: in docs -- https://master.php.net/note/delete/111235/in+docs
Del: other reasons-- https://master.php.net/note/delete/111235
Reject -- https://master.php.net/note/reject/111235
Search -- https://master.php.net/manage/user-notes.php