Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67884 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52207 invoked from network); 26 Jun 2013 15:30:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jun 2013 15:30:23 -0000 Received: from [127.0.0.1] ([127.0.0.1:28400]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id A6/E4-29746-E090BC15 for ; Wed, 26 Jun 2013 11:30:22 -0400 Authentication-Results: pb1.pair.com smtp.mail=j.curcio@icloud.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=j.curcio@icloud.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain icloud.com designates 17.158.161.3 as permitted sender) X-PHP-List-Original-Sender: j.curcio@icloud.com X-Host-Fingerprint: 17.158.161.3 nk11p00mm-asmtp004.mac.com Solaris 10 1203 Received: from [17.158.161.3] ([17.158.161.3:52686] helo=nk11p00mm-asmtp004.mac.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 06/34-29746-5F60BC15 for ; Wed, 26 Jun 2013 11:21:25 -0400 Received: from nk11p00mm-spool004.mac.com ([17.158.161.119]) by nk11p00mm-asmtp004.mac.com (Oracle Communications Messaging Server 7u4-27.04(7.0.4.27.3) 64bit (built Mar 7 2013)) with ESMTP id <0MP00075AAN3LJ70@nk11p00mm-asmtp004.mac.com> for internals@lists.php.net; Wed, 26 Jun 2013 15:21:22 +0000 (GMT) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.10.8794,1.0.431,0.0.0000 definitions=2013-06-26_06:2013-06-26,2013-06-26,1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=1 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=6.0.2-1305010000 definitions=main-1306260099 MIME-version: 1.0 Content-type: multipart/alternative; boundary="Boundary_(ID_myOhCHdU8fWmzkJF5TlEOQ)" Received: from localhost ([17.158.43.22]) by nk11p00mm-spool004.mac.com (Oracle Communications Messaging Server 7u4-23.01(7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTP id <0MP000412ANGN650@nk11p00mm-spool004.mac.com> for internals@lists.php.net; Wed, 26 Jun 2013 15:21:16 +0000 (GMT) To: internals@lists.php.net Date: Wed, 26 Jun 2013 15:20:01 +0000 (GMT) X-Mailer: iCloud Mail (1Q) X-Originating-IP: [75.148.10.129] Message-ID: <4622f2d7-8c09-4a31-943e-7732a9481a9a@me.com> Subject: Gauging Interest:RFC to add map() function From: j.curcio@icloud.com (Jeremy Curcio) --Boundary_(ID_myOhCHdU8fWmzkJF5TlEOQ) Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: quoted-printable Hello,=0A=0AI would like to submit an RFC to add a new function to the PHP= language. The function would be called "map()". The purpose of this funct= ion would be to take an existing value within a range and make it to a cor= responding location within a new range.=0A=0AThe map() method would have 5= required parameters, $originalLow, $originalHigh, $newLow, $newHigh, and = $value.=0A=0Amap() would be implement the following:=0A=0Afunction map($or= iginalLow, $originalHigh, $newLow, $newHigh, $value) {=0A return $newLow += ($value - $originalLow) * ($newHigh - $newLow) / ($originalHigh- $origina= lLow);=0A}=0A=0AExample:=0ALet's say we are teachers and are grading final= exams. We have a policy that the best score is 100, and the worst score i= s a 70. Students scored between 55 and 92. We want to easily re-score the = exams to be within the new score range, so we would use the new map() func= tion. Let's begin with mapping the lowest score:=0A=A0 =A0=A0=0A $newScore= =3D=A0map(55, 92, 70, 100,=A055); //$newScore =3D 70=0A=A0 =A0=A0=0AIf we= have all of our scores in an array:=0A=0A $scores =3D array(71, 65, 55, 8= 5, 88, 86, 92, 77, 73);=0A=0AWe could use a foreach loop to remap each val= ue:=0A=0A $newScores =3D array();=0A foreach($score as $scores) {=0A $new= Scores[] =3D map(55, 92, 70, 100, $score);=0A }=0A var_dump($newScores);=0A= /*=0A array(9) {=0A =A0 [0]=3D>=0A =A0 float(82.972972972973)=0A =A0 [1]=3D= >=0A =A0 float(78.108108108108)=0A =A0 [2]=3D>=0A =A0=A0int(70)=0A =A0 [3]= =3D>=0A =A0 float(94.324324324324)=0A =A0 [4]=3D>=0A =A0 float(96.75675675= 6757)=0A =A0 [5]=3D>=0A =A0 float(95.135135135135)=0A =A0 [6]=3D>=0A =A0 i= nt(100)=0A =A0 [7]=3D>=0A =A0 float(87.837837837838)=0A =A0 [8]=3D>=0A =A0= float(84.594594594595)=0A =A0 }=0A */=0A=0AJust like that, we have the ne= w exam grades that fit our policy, within the proper scale, without having= to do any of the messy math ourselves.=0A=0AWhile I do recognize that thi= s is somewhat trivial to anyone who knows the proper formula, I feel as th= ough it would serve the PHP community well. Much the same as the pow() or = pi() functions do. I appreciate your thoughts on this matter and whether o= r not this is worth pursuing as an RFC.=0A=0AThank you,=0AJeremy Curcio=0A= j.curcio@me.com= --Boundary_(ID_myOhCHdU8fWmzkJF5TlEOQ) Content-type: multipart/related; boundary="Boundary_(ID_whJ3PPNQDnQurbdTNFG+DA)"; type="text/html" --Boundary_(ID_whJ3PPNQDnQurbdTNFG+DA) Content-type: text/html; CHARSET=US-ASCII Content-transfer-encoding: quoted-printable
He= llo,

I would like to submit an RFC to add a new function to the PHP langu= age. The function would be called "map()". The purpose of this function wo= uld be to take an existing value within a range and make it to a correspon= ding location within a new range.

The map() method would have 5 required = parameters, $originalLow, $originalHigh, $newLow, $newHigh, and $value.

=
m= ap() would be implement the following:

function map($originalLow, $originalHigh, $newLow, $newHigh, $value) {
return $newLow + ($value - $originalLow) * = ($newHigh - $newLow) / ($originalHigh- $originalLow);
}

Example:
Let's say we are teachers and are grad= ing final exams. We have a policy that the best score is 100, and the wors= t score is a 70. Students scored between 55 and 92. We want to easily re-s= core the exams to be within the new score range, so we would use the new m= ap() function. Let's begin with mapping the lowest score:
    <= /div>
$newScore= =3D map(55, 92, 70, 100, 55); //$newScore =3D 70
   &nb= sp;

$scores =3D array(71, 65, 55, 85, 88= , 86, 92, 77, 73);

We could use a foreach loop to remap each value:
=

$newScores = =3D array();
foreach($score as $scores) {
$newScores[] =3D map(55, 92, 70, 100, $score);
}
var_dump($newScores);
<= div style=3D"font-family: Helvetica, Arial, Verdana, sans-serif;"> /*
array(9) {
=
&n= bsp; [0]=3D>
  float(82.972972972973)
  [1]=3D>
&= nbsp; float(78.108108108108)
  [2]=3D>
  int(70)
  [3]=3D>
  float(94.324324324324)
  [4]=3D><= /div>
  float(96.756756756757)
  [5]=3D>
  float(95.1= 35135135135)
  [6]=3D>
  int(100)
  [7]=3D><= /div>
  float(87.837837837838)
  [8]=3D>
  float(84.5= 94594594595)
  }
*/

Just like that, we have the new exam grades that= fit our policy, within the proper scale, without having to do any of the = messy math ourselves.

While I do recognize that this is somewhat trivial = to anyone who knows the proper formula, I feel as though it would serve th= e PHP community well. Much the same as the pow() or pi() functions do. I a= ppreciate your thoughts on this matter and whether or not this is worth pu= rsuing as an RFC.

Thank you,
Jeremy Curcio
j.curcio@me.com
= --Boundary_(ID_whJ3PPNQDnQurbdTNFG+DA)-- --Boundary_(ID_myOhCHdU8fWmzkJF5TlEOQ)--