private static function _floatToByte($f)
    {
        // round negatives up to zero
        if ($f <= 0.0) {
            return 0;
        }

        // search for appropriate value
        $lowIndex = 0;
        $highIndex = 255;
        while ($highIndex >= $lowIndex) {
            // $mid = ($highIndex - $lowIndex)/2;
            $mid = ($highIndex + $lowIndex) >> 1;
            $delta = $f - self::$_normTable[$mid];

            if ($delta < 0) {
                $highIndex = $mid-1;
            } elseif ($delta > 0) {
                $lowIndex  = $mid+1;
            } else {
                return $mid; // We got it!
            }
        }

        // round to closest value
        if ($highIndex != 255 
            && $f - self::$_normTable[$highIndex] > self::$_normTable[$highIndex+1] - $f 
        ) {
            return $highIndex + 1;
        } else {
            return $highIndex;
        }
    }
private static function _floatToByte($f)
    {
        // round negatives up to zero
        if ($f <= 0.0) {
            return 0;
        }

        // search for appropriate value
        $lowIndex = 0;
        $highIndex = 255;
        while ($highIndex >= $lowIndex) {
            // $mid = ($highIndex - $lowIndex)/2;
            $mid = ($highIndex + $lowIndex) >> 1;
            $delta = $f - self::$_normTable[$mid];

            if ($delta < 0) {
                $highIndex = $mid-1;
            } elseif ($delta > 0) {
                $lowIndex  = $mid+1;
            } else {
                return $mid; // We got it!
            }
        }

        // round to closest value
        if ($highIndex != 255 
            && $f - self::$_normTable[$highIndex] > self::$_normTable[$highIndex+1] - $f 
        ) {
            return $highIndex + 1;
        } else {
            return $highIndex;
        }
    }
private static function _floatToByte ( $ f ) { // round negatives up to zero if ( $ f <= 0.0 ) { return 0 ; } // search for appropriate value $ lowIndex = 0 ; $ highIndex = 255 ; while ( $ highIndex >= $ lowIndex ) { // $mid = ($highIndex - $lowIndex)/2; $ mid = ( $ highIndex + $ lowIndex ) >> 1 ; $ delta = $ f - self :: $ _normTable [ $ mid ] ; if ( $ delta < 0 ) { $ highIndex = $ mid - 1 ; } elseif ( $ delta > 0 ) { $ lowIndex = $ mid + 1 ; } else { return $ mid ; // We got it! } } // round to closest value if ( $ highIndex != 255 && $ f - self :: $ _normTable [ $ highIndex ] > self :: $ _normTable [ $ highIndex + 1 ] - $ f ) { return $ highIndex + 1 ; } else { return $ highIndex ; } }
Float to byte conversion

@param  integer $b
@return float
Float to byte conversion