Lines Matching +full:n +full:- +full:one

4  * Class for converting between different unit-lengths as specified by
19 * encode conversion data from one system to the next, with a O(n^2)
58 $this->outputPrecision = $output_precision;
59 $this->internalPrecision = $internal_precision;
60 $this->bcmath = !$force_no_bcmath && function_exists('bcmul');
64 * Converts a length object of one unit into another unit.
76 * - If a number is zero-padded as a result of this significant
78 * - If a number contains less than four sigfigs ($outputPrecision)
84 if (!$length->isValid()) {
88 $n = $length->getN();
89 $unit = $length->getUnit();
91 if ($n === '0' || $unit === false) {
110 $sigfigs = $this->getSigFigs($n);
111 if ($sigfigs < $this->outputPrecision) {
112 $sigfigs = $this->outputPrecision;
119 $log = (int)floor(log(abs($n), 10));
120 …$cp = ($log < 0) ? $this->internalPrecision - $log : $this->internalPrecision; // internal precisi…
135 … $factor = $this->div(self::$units[$state][$unit], self::$units[$state][$dest_unit], $cp);
136 $n = $this->mul($n, $factor, $cp);
141 if ($n === '') {
142 $n = '0';
158 // Pre-condition: $i == 0
161 $n = $this->mul($n, self::$units[$state][$dest_state][1], $cp);
165 // One more loop around to convert the unit in the new system.
169 // Post-condition: $unit == $to_unit
175 //echo "<pre>n";
176 //echo "$n\nsigfigs = $sigfigs\nnew_log = $new_log\nlog = $log\nrp = $rp\n</pre>\n";
178 $n = $this->round($n, $sigfigs);
179 if (strpos($n, '.') !== false) {
180 $n = rtrim($n, '0');
182 $n = rtrim($n, '.');
184 return new HTMLPurifier_Length($n, $unit);
189 * @param string $n Decimal number
192 public function getSigFigs($n) argument
194 $n = ltrim($n, '0+-');
195 $dp = strpos($n, '.'); // decimal position
197 $sigfigs = strlen(rtrim($n, '0'));
199 $sigfigs = strlen(ltrim($n, '0.')); // eliminate extra decimal character
201 $sigfigs--;
216 if ($this->bcmath) {
219 return $this->scale((float)$s1 + (float)$s2, $scale);
232 if ($this->bcmath) {
235 return $this->scale((float)$s1 * (float)$s2, $scale);
248 if ($this->bcmath) {
251 return $this->scale((float)$s1 / (float)$s2, $scale);
258 * @param float $n
262 private function round($n, $sigfigs) argument
264 $new_log = (int)floor(log(abs($n), 10)); // Number of digits left of decimal - 1
265 $rp = $sigfigs - $new_log - 1; // Number of decimal places needed
266 $neg = $n < 0 ? '-' : ''; // Negative sign
267 if ($this->bcmath) {
269 $n = bcadd($n, $neg . '0.' . str_repeat('0', $rp) . '5', $rp + 1);
270 $n = bcdiv($n, '1', $rp);
274 $n = bcadd($n, $neg . '5' . str_repeat('0', $new_log - $sigfigs), 0);
275 … $n = substr($n, 0, $sigfigs + strlen($neg)) . str_repeat('0', $new_log - $sigfigs + 1);
277 return $n;
279 return $this->scale(round($n, $sigfigs - $new_log - 1), $rp + 1);
296 // look something like 4652999999999.9234. We grab one more digit
299 $precise = (string)round(substr($r, 0, strlen($r) + $scale), -1);
301 return substr($precise, 0, -1) . str_repeat('0', -$scale + 1);