コード例 #1
0
 function view_non_approve()
 {
     $page = $this->input->get('page');
     if ($page == NULL || is_nan($page)) {
         $page = 1;
     }
     // get non-approved dealers
     $q = array('dealer_level_id' => 0);
     $lim = 15;
     $off = $lim * $page - $lim;
     $dealers = $this->Dealer->list_dealers($q, $lim, $off, 'obj', 'dealer_datetime DESC , dealer_id DESC');
     $rows = $this->Dealer->get_num_rows($q);
     $page_amount = 1;
     if ($rows % $lim == 0 || $rows % $lim == $lim) {
         $page_amount = $rows / $lim;
     } else {
         $page_amount = $rows / $lim + 1;
     }
     $data['dealers'] = $dealers;
     $data['rows'] = $dealers;
     $data['off'] = $off;
     $data['pa'] = (int) $page_amount;
     $data['page'] = $page;
     //load view
     $this->load->view('admin_v/waitApprove', $data);
 }
コード例 #2
0
 private static function fromDouble($value)
 {
     if (is_nan($value)) {
         return 0;
     }
     if ($value < -self::TWO_PWR_63_DBL) {
         return Long::MIN_VALUE;
     }
     if ($value >= self::TWO_PWR_63_DBL) {
         return Long::MAX_VALUE;
     }
     $negative = false;
     if ($value < 0) {
         $negative = true;
         $value = -$value;
     }
     $a2 = 0;
     if ($value >= self::TWO_PWR_44_DBL) {
         $a2 = (int) ($value / self::TWO_PWR_44_DBL);
         $value -= $a2 * self::TWO_PWR_44_DBL;
     }
     $a1 = 0;
     if ($value >= self::TWO_PWR_22_DBL) {
         $a1 = (int) ($value / self::TWO_PWR_22_DBL);
         $value -= $a1 * self::TWO_PWR_22_DBL;
     }
     $a0 = (int) $value;
     $result = $a2 << 44 | $a1 << 22 | $a0;
     if ($negative) {
         $result = -$result;
     }
     return $result;
 }
コード例 #3
0
    public function find($n)
    {
        if (isset($n) && !is_nan($n)) {
            $n = intval($n);
            $query = '	SELECT * 
							FROM message 
							ORDER BY rate DESC 
							LIMIT ' . $n;
        } else {
            $query = '	SELECT * 
							FROM message 
							ORDER BY rate DESC';
        }
        $res = $this->db->query($query);
        if ($res) {
            $messages = $res->fetchAll(PDO::FETCH_CLASS, "Message", array($this->db));
            if (count($messages) > 0) {
                return $messages;
            } else {
                throw new Exception('No message to show');
            }
        } else {
            throw new Exception('Error 01 : Database error');
        }
    }
コード例 #4
0
ファイル: Base64.inc.php プロジェクト: selenus/dataserver
 public static function encode($input)
 {
     $output = "";
     $chr1 = $chr2 = $chr3 = $enc1 = $enc2 = $enc3 = $enc4 = "";
     $i = 0;
     $input = self::utf8_encode($input);
     while ($i < mb_strlen($input)) {
         $chr1 = Z_Unicode::charCodeAt($input, $i++);
         $chr2 = Z_Unicode::charCodeAt($input, $i++);
         $chr3 = Z_Unicode::charCodeAt($input, $i++);
         $enc1 = $chr1 >> 2;
         $enc2 = ($chr1 & 3) << 4 | $chr2 >> 4;
         $enc3 = ($chr2 & 15) << 2 | $chr3 >> 6;
         $enc4 = $chr3 & 63;
         if (is_nan($chr2)) {
             $enc3 = $enc4 = 64;
         } else {
             if (is_nan($chr3)) {
                 $enc4 = 64;
             }
         }
         $output = $output . Z_Unicode::charAt(self::$keyStr, $enc1) . Z_Unicode::charAt(self::$keyStr, $enc2) . Z_Unicode::charAt(self::$keyStr, $enc3) . Z_Unicode::charAt(self::$keyStr, $enc4);
     }
     return $output;
 }
コード例 #5
0
ファイル: datapump.php プロジェクト: aldridged/gtg-gts
function handleSpeed($link, $devid, $lat, $long)
{
    // Find previous location event for devid
    $res = mysql_query("SELECT statusCode,timestamp,latitude,longitude FROM EventData WHERE (deviceID='" . $devid . "' AND statusCode=61472) ORDER BY timestamp DESC LIMIT 1", $link);
    // If there is a previous location
    if (mysql_num_rows($res) > 0) {
        list($statusCode, $lasttime, $lastlat, $lastlong) = mysql_fetch_row($res);
        // get time diff
        $deltatime = time() - $lasttime;
        // calculate heading and speed
        $heading = calculateBearing($lastlat, $lastlong, $lat, $long);
        if (is_nan($heading)) {
            $heading = 0;
        }
        $speed = calculateSpeed($lastlat, $lastlong, $lat, $long, $deltatime);
        if (is_nan($speed)) {
            $speed = 0;
        }
        $retval = array($speed, $heading);
    }
    if (isset($retval)) {
        return $retval;
    } else {
        return array(0, 0);
    }
}
コード例 #6
0
ファイル: Base64.php プロジェクト: nirnanaaa/xlix
 public function base64_encode($input)
 {
     $output = "";
     $chr1 = $chr2 = $chr3 = $enc1 = $enc2 = $enc3 = $enc4 = null;
     $i = 0;
     //        $input = self::utf8_encode($input);
     while ($i < strlen($input)) {
         $chr1 = ord($input[$i++]);
         $chr2 = ord($input[$i++]);
         $chr3 = ord($input[$i++]);
         $enc1 = $chr1 >> 2;
         $enc2 = ($chr1 & 3) << 4 | $chr2 >> 4;
         $enc3 = ($chr2 & 15) << 2 | $chr3 >> 6;
         $enc4 = $chr3 & 63;
         if (is_nan($chr2)) {
             $enc3 = $enc4 = 64;
         } else {
             if (is_nan($chr3)) {
                 $enc4 = 64;
             }
         }
         $output .= self::$BinaryMap[$enc1] . self::$BinaryMap[$enc2] . self::$BinaryMap[$enc3] . self::$BinaryMap[$enc4];
     }
     return $output;
 }
コード例 #7
0
ファイル: IntegerType.php プロジェクト: esperecyan/webidl
 /**
  * 与えられた値を整数型に変換して返します。
  * @link http://www.hcn.zaq.ne.jp/___/WEB/WebIDL-ja.html#es-integers Web IDL (第2版 — 日本語訳)
  * @param boolean|integer|float|string|resource|\GMP|\SplInt $value
  * @param string $type byte、octet、short、unsigned short、long、unsigned long、long long、unsigned long long
  * @param integer|float $min 浮動小数点型で正確に扱える整数の範囲よりも、整数型で扱える整数の範囲が狭ければ (整数型が32bitである環境なら) 浮動小数点数。
  * @param integer|float $max 浮動小数点型で正確に扱える整数の範囲よりも、整数型で扱える整数の範囲が狭ければ (整数型が32bitである環境なら) 浮動小数点数。
  * @param integer $bits
  * @param booelan $signed
  * @param string $extendedAttribute 拡張属性。[EnforceRange] か [Clamp] のいずれか。
  * @return integer|float 整数型の範囲を超える場合は浮動小数点数。
  * @throws \InvalidArgumentException 配列、NULL が与えられた場合。または、GMP、SplInt 以外のオブジェクトが与えられた場合。
  * @throws \DomainException $extendedAttribute が [EnforceRange]、かつ与えられたの値が $min 〜 $max に収まらなかった場合。
  */
 private static function toInteger($value, $type, $min, $max, $bits, $signed, $extendedAttribute = null)
 {
     /** @var string 要求される型。 */
     $expectedType = sprintf('%s (an integer in the range of %s to %s)', $type, is_float($min) ? number_format($min, 0, '', '') : $min, is_float($max) ? number_format($max, 0, '', '') : $max);
     if (!self::isIntegerCastable($value)) {
         throw new \InvalidArgumentException(ErrorMessageCreator::create($value, $expectedType));
     }
     if ($value instanceof \GMP || is_resource($value) && get_resource_type($value) === 'GMP integer') {
         // GMP数であれば、あらかじめ文字列に変換しておく
         $value = gmp_strval($value);
     }
     /** @var integer|float 与えられた値の数値表現。整数型の範囲を超える場合は浮動小数点数。整数値となる場合、小数部があれば0方向へ丸められる。 */
     $number = is_float($value) || (double) $value < self::$phpIntMin || (double) $value > PHP_INT_MAX ? (double) $value : (int) $value;
     if ($extendedAttribute === '[EnforceRange]') {
         /** @var integer|float 与えられた値の整数表現。整数型の範囲を超える場合は浮動小数点数。 */
         $integer = self::roundTowardZero($number);
         if (!is_finite($number) || $integer < $min || $integer > $max) {
             throw new \DomainException(ErrorMessageCreator::create($value, $expectedType));
         }
     } elseif (!is_nan($number) && $extendedAttribute === '[Clamp]') {
         $number = min(max($number, $min), $max);
         $integer = is_float($number) ? round($number, 0, PHP_ROUND_HALF_EVEN) : $number;
     } elseif (!is_finite($number)) {
         $integer = 0;
     } else {
         $integer = self::modulo(self::roundTowardZero($number), pow(2, $bits));
         if ($signed && $integer >= pow(2, $bits - 1)) {
             $integer -= pow(2, $bits);
         }
     }
     return is_float($integer) && $integer >= self::$phpIntMin && $integer <= PHP_INT_MAX ? (int) $integer : $integer;
 }
コード例 #8
0
 function view_payments()
 {
     $status = $this->input->get('st');
     $page = $this->input->get('page');
     if ($page == NULL || $page == '' || is_nan($page)) {
         $page = 1;
     }
     $p_arr = array();
     //ftilter
     if ($status != NULL && is_numeric($status)) {
         $p_arr['order_order_status_id'] = $status;
     } else {
         $status = "";
     }
     $off = $this->lim * $page - $this->lim;
     $rows = $this->Payment->get_num_rows($p_arr);
     if ($rows % $this->lim == 0 || $rows % $this->lim == $this->lim) {
         $page_amount = $rows / $this->lim;
     } else {
         $page_amount = $rows / $this->lim + 1;
     }
     $payments = $this->Payment->list_payments($p_arr, $this->lim, $off, 'obj');
     $sts = $this->Order_status->list_order_status();
     $data['payments'] = $payments;
     $data['sts'] = $sts;
     $data['osid'] = $status;
     $data['page_amount'] = $page_amount;
     $data['page'] = $page;
     $data['rows'] = $rows;
     $data['off'] = $off;
     $this->load->view('admin_v/allPayment', $data);
 }
コード例 #9
0
 /**
  * Get the total amount of money raised for today
  * @param string $timeZoneOffset The timezone to request the total for
  * @param string $today The current date in the requested time zone, e.g. '2011-12-16'
  * @param int $fudgeFactor How much to adjust the total by
  * @return integer
  */
 private function getTodaysTotal($timeZoneOffset, $today, $fudgeFactor = 0)
 {
     global $wgMemc, $egFundraiserStatisticsMinimum, $egFundraiserStatisticsMaximum, $egFundraiserStatisticsCacheTimeout;
     // Delete this block once there is timezone support in the populating script
     $setTimeZone = date_default_timezone_set('UTC');
     $today = date('Y-m-d');
     // Get the current date in UTC
     $timeZoneOffset = '+00:00';
     $key = wfMemcKey('fundraiserdailytotal', $timeZoneOffset, $today, $fudgeFactor);
     $cache = $wgMemc->get($key);
     if ($cache != false && $cache != -1) {
         return $cache;
     }
     // Use MediaWiki slave database
     $dbr = wfGetDB(DB_SLAVE);
     $result = $dbr->select('public_reporting_days', 'round( prd_total ) AS total', array('prd_date' => $today), __METHOD__);
     $row = $dbr->fetchRow($result);
     if ($row['total'] > 0) {
         $total = $row['total'];
     } else {
         $total = 0;
     }
     // Make sure the fudge factor is a number
     if (is_nan($fudgeFactor)) {
         $fudgeFactor = 0;
     }
     // Add the fudge factor to the total
     $total += $fudgeFactor;
     $wgMemc->set($key, $total, $egFundraiserStatisticsCacheTimeout);
     return $total;
 }
コード例 #10
0
ファイル: Numeric.php プロジェクト: millolab/quaver-core
 public function validateValue($value, $field, $model)
 {
     $value = $this->cast($value, $field, $model);
     $def = $model->fields[$field];
     if (is_null($value)) {
         $required = $model->checkFieldOptionCondition($field, 'required', false);
         if (!$required || !$model->exists() && $model->primaryKey === $field) {
             return true;
         }
         $model->setError($field, 'error-required');
         return false;
     } else {
         if (is_nan($value)) {
             $model->setError($field, 'error-numeric');
             return false;
         }
         if (isset($def['gt']) && $value <= $def['gt']) {
             $model->setError($field, 'error-numeric-gt');
             return false;
         }
         if (isset($def['gte']) && $value < $def['gt']) {
             $model->setError($field, 'error-numeric-gte');
             return false;
         }
         if (isset($def['lt']) && $value >= $def['gt']) {
             $model->setError($field, 'error-numeric-lt');
             return false;
         }
         if (isset($def['lte']) && $value > $def['gt']) {
             $model->setError($field, 'error-numeric-lte');
             return false;
         }
     }
     return parent::validateValue($value, $field, $model);
 }
コード例 #11
0
 protected function dumpScalar($a)
 {
     switch (true) {
         case null === $a:
             $this->line .= 'null';
             break;
         case true === $a:
             $this->line .= 'true';
             break;
         case false === $a:
             $this->line .= 'false';
             break;
         case INF === $a:
             $this->line .= '"n`INF"';
             break;
         case -INF === $a:
             $this->line .= '"n`-INF"';
             break;
         case is_nan($a):
             $this->line .= '"n`NAN"';
             break;
         case $a > 9007199254740992.0 && is_int($a):
             $a = '"n`' . $a . '"';
             // JavaScript max integer is 2^53
         // JavaScript max integer is 2^53
         default:
             $this->line .= (string) $a;
             break;
     }
 }
コード例 #12
0
 /**
 * Returns a list of all stations according to the lang variable and what the API returns. Normally it will have these variables:
 * array[i] -> name
            -> locationX
            -> locationY
            -> standardname
 */
 private function getClosestStations($y, $x, $system)
 {
     include "config.php";
     //check if the stationslist hasn't been loaded yet and load the systems
     if (!isset($this->{$system})) {
         try {
             $args = array("system" => $system, "lang" => "NL");
             $this->{$system} = APICall::execute("stations", $args);
         } catch (Exception $e) {
             throw $e;
         }
     }
     $output = array();
     $stations = $this->{$system};
     //Loop and check if distance is smaller then the vicinity, you only want to get stations nearby
     foreach ($stations["station"] as $station) {
         $dist = $this->distance($x, $station["locationX"], $y, $station["locationY"]);
         if (!is_nan($dist) && $dist < $vicinity) {
             $station["distance"] = floor($dist * 1000);
             //in meters
             $output[sizeof($output)] = $station;
         }
     }
     $output = $this->removeDuplicates($output);
     return $output;
 }
コード例 #13
0
ファイル: calculate.php プロジェクト: vid-d/calculators
 function brix_to_gravity()
 {
     if (is_nan($this->brix)) {
         exit;
     }
     $this->output['b_to_g'] = $this->brix / (258.6 - $this->brix / 258.2 * 227.1) + 1;
 }
コード例 #14
0
 /**
  * Parses the request.
  *
  * @return void
  */
 public function parse()
 {
     $filterNode = null;
     $limit = $this->xpath->evaluate('number(/card:addressbook-query/card:limit/card:nresults)');
     if (is_nan($limit)) {
         $limit = null;
     }
     $filter = $this->xpath->query('/card:addressbook-query/card:filter');
     if ($filter->length !== 1) {
         throw new Sabre_DAV_Exception_BadRequest('Only one filter element is allowed');
     }
     $filter = $filter->item(0);
     $test = $this->xpath->evaluate('string(@test)', $filter);
     if (!$test) {
         $test = self::TEST_ANYOF;
     }
     if ($test !== self::TEST_ANYOF && $test !== self::TEST_ALLOF) {
         throw new Sabre_DAV_Exception_BadRequest('The test attribute must either hold "anyof" or "allof"');
     }
     $propFilters = array();
     $propFilterNodes = $this->xpath->query('card:prop-filter', $filter);
     for ($ii = 0; $ii < $propFilterNodes->length; $ii++) {
         $propFilters[] = $this->parsePropFilterNode($propFilterNodes->item($ii));
     }
     $this->filters = $propFilters;
     $this->limit = $limit;
     $this->requestedProperties = array_keys(Sabre_DAV_XMLUtil::parseProperties($this->dom->firstChild));
     $this->test = $test;
 }
コード例 #15
0
ファイル: topicFunctions.php プロジェクト: kubar123/diploma
function validateData($data, $type)
{
    //text check
    if ($type == 'abc') {
        if ($data == "") {
            die("Invalid type");
        }
        if ($data == " ") {
            die("Invalid type");
        }
        if ($data == "  ") {
            die("Invalid type");
        }
        // everything is ok.
        //number check
    } else {
        if ($type == 123) {
            if ($data == '') {
                die("Invalid type");
            }
            if (is_nan($data)) {
                die("Invalid type");
            }
        }
    }
}
コード例 #16
0
ファイル: phraseadate.php プロジェクト: luisbrito/Phraseanet
 /**
  *
  * @param  DateTime $date
  * @return string
  */
 public function getPrettyString(DateTime $date = null)
 {
     if (is_null($date)) {
         return null;
     }
     $compareTo = new DateTime('now');
     $diff = $compareTo->format('U') - $date->format('U');
     $dayDiff = floor($diff / 86400);
     if (is_nan($dayDiff) || $dayDiff > 365000) {
         return '';
     }
     $date_string = $this->formatDate($date, $this->app['locale'], 'DAY_MONTH');
     if ($dayDiff == 0) {
         if ($diff < 60) {
             return $this->app->trans('phraseanet::temps:: a l\'instant');
         } elseif ($diff < 120) {
             return $this->app->trans('phraseanet::temps:: il y a une minute');
         } elseif ($diff < 3600) {
             return $this->app->trans('phraseanet::temps:: il y a %quantity% minutes', ['%quantity%' => floor($diff / 60)]);
         } elseif ($diff < 7200) {
             return $this->app->trans('phraseanet::temps:: il y a une heure');
         } elseif ($diff < 86400) {
             return $this->app->trans('phraseanet::temps:: il y a %quantity% heures', ['%quantity%' => floor($diff / 3600)]);
         }
     } elseif ($dayDiff == 1) {
         return $this->app->trans('phraseanet::temps:: hier');
     } elseif ($dayDiff < 365 && $dayDiff > 0) {
         return $date_string;
     } else {
         return $this->formatDate($date, $this->app['locale'], 'DAY_MONTH_YEAR');
     }
 }
コード例 #17
0
ファイル: Continuous.php プロジェクト: markrogoyski/math-php
 /**
  * The Inverse CDF of the distribution
  *
  * For example, if the calling class CDF definition is CDF($x, $d1, $d2)
  * than the inverse is called as inverse($target, $d1, $d2)
  *
  * @param number $target   The area for which we are trying to find the $x
  * @param array ...$params List of all the parameters that are needed for the CDF of the
  *   calling class. This list must be absent the $x parameter.
  *
  * @todo check the parameter ranges.
  * @return $number
  */
 public static function inverse($target, ...$params)
 {
     $initial = static::mean(...$params);
     if (is_nan($initial)) {
         $initial = static::median(...$params);
     }
     array_unshift($params, $initial);
     $classname = get_called_class();
     $CDF_callback = [$classname, 'CDF'];
     $PDF_callback = [$classname, 'PDF'];
     $tolerance = 1.0E-10;
     $dif = $tolerance + 1;
     $guess = $params[0];
     while ($dif > $tolerance) {
         // load the guess into the arguments
         $params[0] = $guess;
         $y = call_user_func_array($CDF_callback, $params);
         // Since the CDF is the integral of the PDF, the PDF is the derivative of the CDF
         $slope = call_user_func_array($PDF_callback, $params);
         $del_y = $target - $y;
         $guess = $del_y / $slope + $guess;
         $dif = abs($del_y);
     }
     return $guess;
 }
コード例 #18
0
 /**
  * Return the ulp for the given float argument.  The ulp is the
  * difference between the argument and the next larger float.  Note
  * that the sign of the float argument is ignored, that is,
  * ulp(x) == ulp(-x).  If the argument is a NaN, then NaN is returned.
  * If the argument is an infinity, then +Inf is returned.  If the
  * argument is zero (either positive or negative), then
  * {@link Float#MIN_VALUE} is returned.
  *
  * @param float						$f 
  *
  * @return float 
  */
 public static function ulp($f)
 {
     if (is_nan($f)) {
         return $f;
     }
     if (is_infinite($f)) {
         return INF;
     }
     // This handles both +0.0 and -0.0.
     if ($f == 0.0) {
         return self::implode(0, 0, 1);
         //returns closest value to 0 possible without being 0
     }
     $bits = self::explode($f);
     $bits[0] = 0;
     $mantissa = $bits[2];
     $exponent = $bits[1];
     // Denormal number, so the answer is easy.
     if ($bits[1] == 0) {
         $bits[2] = 1;
         //set fraction to smallest possible value
         return self::implode($bits);
     }
     // Conceptually we want to have '1' as the mantissa.  Then we would
     // shift the mantissa over to make a normal number.  If this underflows
     // the exponent, we will make a denormal result.
     $bits[1] -= 23;
     $bits[2] = 0;
     if ($bits[1] == 0) {
         $bits[2] = 1 << -($bits[1] - 1);
         $bits[1] = 0;
     }
     return self::implode($bits);
 }
コード例 #19
0
 /**
  * @param mixed $value
  * @param int   $depth
  *
  * @return string
  */
 public static function stringify($value, $depth = 1)
 {
     if ($depth >= self::$maxDepthStringify) {
         return self::$maxReplacementStringify;
     }
     if (is_array($value)) {
         return static::stringifyArray($value, $depth);
     }
     if (is_object($value)) {
         return static::stringifyObject($value, $depth);
     }
     if (is_resource($value)) {
         return sprintf('`[resource] (%s)`', get_resource_type($value));
     }
     if (is_float($value)) {
         if (is_infinite($value)) {
             return ($value > 0 ? '' : '-') . 'INF';
         }
         if (is_nan($value)) {
             return 'NaN';
         }
     }
     $options = 0;
     if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
         $options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
     }
     return @json_encode($value, $options) ?: $value;
 }
コード例 #20
0
 public function logQuery(array $query)
 {
     dump($query);
     exit;
     if ($this->logger === NULL) {
         return;
     }
     if (isset($query['batchInsert']) && NULL !== $this->batchInsertTreshold && $this->batchInsertTreshold <= $query['num']) {
         $query['data'] = '**' . $query['num'] . ' item(s)**';
     }
     array_walk_recursive($query, function (&$value, $key) {
         if ($value instanceof \MongoBinData) {
             $value = base64_encode($value->bin);
             return;
         }
         if (is_float($value) && is_infinite($value)) {
             $value = ($value < 0 ? '-' : '') . 'Infinity';
             return;
         }
         if (is_float($value) && is_nan($value)) {
             $value = 'NaN';
             return;
         }
     });
     $this->logger->debug($this->prefix . json_encode($query));
 }
コード例 #21
0
ファイル: fun.php プロジェクト: azder/fun-php
/**
 * @param $value
 *
 * @return bool|null
 */
function tril($value)
{
    if (null === $value || false === $value || true === $value) {
        return $value;
    }
    if (is_array($value)) {
        return !empty($value);
    }
    if (is_object($value)) {
        return true;
    }
    if (is_double($value) && is_nan($value)) {
        return null;
    }
    $value = trim(strtolower($value));
    if (in_array($value, ['', 'null', 'maybe'])) {
        return null;
    }
    if (in_array($value, ['no', 'off', '0', 'false'])) {
        return false;
    }
    if (in_array($value, ['yes', 'on', '1', 'true'])) {
        return true;
    }
    return boolval($value);
}
コード例 #22
0
ファイル: Currency.php プロジェクト: leodido/moneylaundry
 /**
  * Returns the result of filtering $value
  *
  * @param mixed $value
  * @return mixed
  */
 public function filter($value)
 {
     $unfilteredValue = $value;
     if (is_float($value) && !is_nan($value) && !is_infinite($value)) {
         ErrorHandler::start();
         $formatter = $this->getFormatter();
         $currencyCode = $this->setupCurrencyCode();
         $result = $formatter->formatCurrency($value, $currencyCode);
         ErrorHandler::stop();
         // FIXME: verify that this, given the initial IF condition, never happens
         // if ($result === false) {
         // return $unfilteredValue;
         // }
         // Retrieve the precision internally used by the formatter (i.e., depends from locale and currency code)
         $precision = $formatter->getAttribute(\NumberFormatter::FRACTION_DIGITS);
         // $result is considered valid if the currency's fraction digits can accomodate the $value decimal precision
         // i.e. EUR (fraction digits = 2) must NOT allow double(1.23432423432)
         $isFloatScalePrecise = $this->isFloatScalePrecise($value, $precision, $this->formatter->getAttribute(\NumberFormatter::ROUNDING_MODE));
         if ($this->getScaleCorrectness() && !$isFloatScalePrecise) {
             return $unfilteredValue;
         }
         return $result;
     }
     return $unfilteredValue;
 }
コード例 #23
0
ファイル: titulo.php プロジェクト: vallejos/samples
 public function setFont($fuente)
 {
     if (is_nan($fuente)) {
         $fuente = imageloadfont($fuente);
     }
     $this->fuente = $fuente;
 }
コード例 #24
0
 /**
  * ensure the amount is rounded to two decimal places.
  *
  * @param  mixed any numeric value
  * @return float|null rounded to 2 places, null if amount is not numeric
  */
 protected function sanitizeAmount($amount)
 {
     if (is_numeric($amount) && !is_nan($amount)) {
         return round($amount, 2, PHP_ROUND_HALF_UP);
     }
     return null;
 }
コード例 #25
0
 /**
  * Process the Truncate operator.
  * 
  * @return integer|null The truncated value or NULL if the sub-expression is NaN or if the sub-expression is NULL.
  * @throws OperatorProcessingException
  */
 public function process()
 {
     $operands = $this->getOperands();
     if ($operands->containsNull() === true) {
         return null;
     }
     if ($operands->exclusivelySingle() === false) {
         $msg = "The Truncate operator only accepts operands with a single cardinality.";
         throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
     }
     if ($operands->exclusivelyNumeric() === false) {
         $msg = "The Truncate operator only accepts operands with an integer or float baseType.";
         throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
     }
     $operand = $operands[0];
     if (is_nan($operand->getValue())) {
         return null;
     } else {
         if (is_infinite($operand->getValue())) {
             return new Float(INF);
         } else {
             return new Integer(intval($operand->getValue()));
         }
     }
 }
コード例 #26
0
 public function alteraSenhaRest()
 {
     $data = $this->request->post();
     $fachada = Fachada::getInstance();
     $id = (int) $fachada->decript($data["userID"]);
     if (is_nan($id)) {
         throw new InvalidArgumentException();
     }
     $userVO = new UsuarioVO();
     $userVO->setIdUsuario($id);
     /*
     *
      senhaAtual
        novaSenha
        repetirNovaSenha
        userID
     *
     */
     $vo = $fachada->selectOneByID($userVO);
     if ($vo) {
         $md5SenhaAtual = md5($data['senhaAtual']);
         $boo = $md5SenhaAtual == $vo->getSenha();
         if (!$boo) {
             throw new InvalidArgumentException();
         }
         $vo->setSenha(md5($data['novaSenha']));
         try {
             $fachada->updateUser($vo);
         } catch (Exception $e) {
             var_dump($e);
         }
     }
     echo $this->getResponse($vo);
 }
コード例 #27
0
ファイル: var_info.func.php プロジェクト: tfont/skyfire
function var_info($value)
{
    if ($value === NULL) {
        return 'null';
    }
    if (is_array($value)) {
        if (is_callable($value)) {
            return 'callable array';
        }
        return 'array';
    }
    if (is_bool($value)) {
        return $value ? 'true' : 'false';
    }
    if (is_float($value)) {
        if (is_infinite($value)) {
            return 'infinite float';
        }
        if (is_nan($value)) {
            return 'invalid float';
        }
        if ($value > 0.0) {
            return 'positive float';
        }
        if ($value < 0.0) {
            return 'negative float';
        }
        return 'zero float';
    }
    if (is_int($value)) {
        if ($value > 0) {
            return 'positive int';
        }
        if ($value < 0) {
            return 'negative int';
        }
        return 'zero int';
    }
    if (is_object($value)) {
        return get_class($value);
    }
    if (is_string($value)) {
        if (is_numeric($value)) {
            return 'numeric string';
        }
        if (is_callable($value)) {
            return 'callable string';
        }
        return 'string';
    }
    $resource_type = @get_resource_type($value);
    if (is_resource($value)) {
        return $resource_type . ' resource';
    }
    if (strtolower($resource_type) == 'unknown') {
        return 'invalid resource';
    }
    return 'unknown';
}
コード例 #28
0
 public function __construct($supportAssocArray = false)
 {
     $this->supportAssocArray = $supportAssocArray;
     $this->groundHandlers = [gettype('') => function ($obj, $asKey) {
         $bad = ['~' => true, '^' => true];
         return strlen($obj) > 0 && isset($bad[$obj[0]]) ? '~' . $obj : $obj;
     }, gettype(1) => function ($obj, $asKey) {
         return $asKey ? '~i' . $obj : $obj;
     }, gettype(1.1) => function ($obj, $asKey) {
         if (is_nan($obj)) {
             return '~zNaN';
         }
         if ($obj == INF) {
             return '~zINF';
         }
         if ($obj == -INF) {
             return '~z-INF';
         }
         return $asKey ? '~d' . $obj : $obj;
     }, gettype(true) => function ($obj, $asKey) {
         return $asKey ? '~?' . ($obj ? 't' : 'f') : $obj;
     }, gettype(null) => function ($obj, $asKey) {
         return $asKey ? '~_' : $obj;
     }, gettype([]) => function ($obj, $_) {
         $result = [];
         if ($this->supportAssocArray && $this->isAssoc($obj)) {
             foreach ($obj as $key => $value) {
                 $result[] = $this->handle($key, true);
                 $result[] = $this->handle($value, false);
             }
             array_unshift($result, '^ ');
             return $result;
         }
         foreach ($obj as $value) {
             $result[] = $this->handle($value);
         }
         return $result;
     }, Bytes::class => function ($obj, $_) {
         return '~b' . base64_encode((string) $obj);
     }, Map::class => function ($obj, $_) {
         $result = [];
         $handledValue = null;
         $compositeKey = false;
         $i = 0;
         foreach ($obj->toArray() as $value) {
             $asKey = $i++ % 2 == 0;
             $handledValue = $this->handle($value, $asKey);
             if ($asKey && !$compositeKey && is_array($handledValue)) {
                 $compositeKey = true;
             }
             $result[] = $handledValue;
         }
         if ($compositeKey) {
             return ['~#cmap', $result];
         }
         array_unshift($result, '^ ');
         return $result;
     }];
 }
コード例 #29
0
ファイル: suncalc.php プロジェクト: gregseth/suncalc-php
function fromJulian($j)
{
    if (!is_nan($j)) {
        $dt = new DateTime("@" . round(($j + 0.5 - J1970) * daySec));
        $dt->setTimezone((new DateTime())->getTimezone());
        return $dt;
    }
}
コード例 #30
0
 /**
  * @param mixed $data
  * @return int|bool|string|null|array
  */
 protected function normalize($data, int $depth = 0)
 {
     if ($depth > 9) {
         return 'Over 9 levels deep, aborting normalization';
     }
     if (null === $data || is_scalar($data)) {
         if (is_float($data)) {
             if (is_infinite($data)) {
                 return ($data > 0 ? '' : '-') . 'INF';
             }
             if (is_nan($data)) {
                 return 'NaN';
             }
         }
         return $data;
     }
     if (is_array($data) || $data instanceof \Traversable) {
         $normalized = [];
         $count = 1;
         if ($data instanceof \Generator && !$data->valid()) {
             return array('...' => 'Generator is already consumed, aborting');
         }
         foreach ($data as $key => $value) {
             if ($count++ >= 1000) {
                 $normalized['...'] = 'Over 1000 items (' . ($data instanceof \Generator ? 'generator function' : count($data) . ' total') . '), aborting normalization';
                 break;
             }
             $normalized[$key] = $this->normalize($value, $depth + 1);
         }
         return $normalized;
     }
     if ($data instanceof \DateTimeInterface) {
         return $this->formatDate($data);
     }
     if (is_object($data)) {
         if ($data instanceof Throwable) {
             return $this->normalizeException($data, $depth);
         }
         if ($data instanceof \JsonSerializable) {
             $value = $data->jsonSerialize();
         } elseif (method_exists($data, '__toString')) {
             $value = $data->__toString();
         } else {
             // the rest is normalized by json encoding and decoding it
             $encoded = $this->toJson($data, true);
             if ($encoded === false) {
                 $value = 'JSON_ERROR';
             } else {
                 $value = json_decode($encoded, true);
             }
         }
         return [get_class($data) => $value];
     }
     if (is_resource($data)) {
         return sprintf('[resource(%s)]', get_resource_type($data));
     }
     return '[unknown(' . gettype($data) . ')]';
 }