Exemple #1
0
 public static function pack($value)
 {
     if ($value === null) {
         return null;
     }
     $valueStr = strtolower((string) $value);
     $expOffset = 0;
     if (strpos($valueStr, 'e') !== false) {
         $parts = explode("e", $valueStr);
         $valueStr = $parts[0];
         $expOffset = (int) $parts[1];
     }
     $parts = explode(".", $valueStr);
     $hasFraction = count($parts) > 1;
     $digits = (int) ($hasFraction ? $parts[0] . $parts[1] : $parts[0]);
     $exp = $hasFraction ? strlen($parts[1]) : 0;
     $exp -= $expOffset;
     $expBytes = pack('N', $exp);
     // TODO: This always encodes as 64 bit. Find a way to use less bytes
     $digitBytes = LongType::pack($digits);
     return $expBytes . $digitBytes;
 }
 public function __construct($value)
 {
     parent::__construct($value, true);
 }