Re: Gauging Interest:RFC to add map() function

From: Date: Wed, 26 Jun 2013 16:09:40 +0000
Subject: Re: Gauging Interest:RFC to add map() function
References: 1  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
I am curious with something that is so easy; why would you want it in core?
A lot of the Math Functions could be considered "so easy". abs() could be written out as:
    function abs($n) {
        if ($n >= 0) return $n;
        else return $n*-1;
    }
pi() could be replaced by simply setting a global variable equal to 3.14159265358979 floor() could be written out as:
    function floor($n) {
        $stop = strpos($n, '.');
        if ($stop !== false) return substr($n,0,$stop);
        else return $n
    }
ceil() could be written out as:
    function ceila($n) {
        $stop = strpos($n, '.');
        if ($stop !== false) return 1+substr($n,0,$stop);
        else return $n;
    }
The above examples are just a few that stick out to me I'm sure that looking through the list of available math functions would provide a few more examples. Keeping these examples in mind, I don't follow the logic of range mapping being too easy to implement manually whenever it is needed to not warrant being included in core.

Thread (15 messages)

« previous php.internals (#67889) next »