Esempio n. 1
0
    }
    if ($numValidChars > 0) {
        $value = substr($value, 0, $numValidChars);
        return floatval(base_convert($value, $radix, 10));
    }
    return NAN;
}, 'parseFloat' => function ($value) {
    $value = to_string($value);
    $value = preg_replace('/^[\\t\\x0B\\f \\xA0\\r\\n]+/', '', $value);
    $sign = $value[0] === '-' ? -1 : 1;
    $value = preg_replace('/^[+-]/', '', $value);
    if (preg_match('/^(\\d+\\.\\d*|\\.\\d+|\\d+)e([+-]?[0-9]+)/i', $value, $m)) {
        return (double) ($sign * $m[1] * pow(10, $m[2]));
    }
    if (preg_match('/^(\\d+\\.\\d*|\\.\\d+|\\d+)/i', $value, $m)) {
        return (double) ($m[0] * $sign);
    }
    return NAN;
}, 'isNaN' => function ($value) {
    return is_nan(to_number($value));
});
Number::$protoMethods = array('valueOf' => function () {
    $self = Func::getContext();
    return $self->value;
}, 'toString' => function ($radix = null) {
    $self = Func::getContext();
    //todo: radix
    return to_string($self->value);
});
Number::$protoObject = new Object();
Number::$protoObject->setMethods(Number::$protoMethods, true, false, true);