PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Calculation / MathTrig / Base.php

Base.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Calculation/MathTrig/Base.php

69 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
4
5 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
6 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Exception;
7 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
8
9 class Base
10 {
11 use ArrayEnabled;
12
13 /**
14 * BASE.
15 *
16 * Converts a number into a text representation with the given radix (base).
17 *
18 * Excel Function:
19 * BASE(Number, Radix [Min_length])
20 *
21 * @param mixed $number expect float
22 * Or can be an array of values
23 * @param mixed $radix expect float
24 * Or can be an array of values
25 * @param mixed $minLength expect int or null
26 * Or can be an array of values
27 *
28 * @return array<mixed>|string the text representation with the given radix (base)
29 * If an array of numbers is passed as an argument, then the returned result will also be an array
30 * with the same dimensions
31 */
32 public static function evaluate($number, $radix, $minLength = null)
33 {
34 if (is_array($number) || is_array($radix) || is_array($minLength)) {
35 return self::evaluateArrayArguments([self::class, __FUNCTION__], $number, $radix, $minLength);
36 }
37
38 try {
39 $number = (float) floor(Helpers::validateNumericNullBool($number));
40 $radix = (int) Helpers::validateNumericNullBool($radix);
41 } catch (Exception $e) {
42 return $e->getMessage();
43 }
44
45 return self::calculate($number, $radix, $minLength);
46 }
47
48 /**
49 * @param mixed $minLength
50 */
51 private static function calculate(float $number, int $radix, $minLength): string
52 {
53 if ($minLength === null || is_numeric($minLength)) {
54 if ($number < 0 || $number >= 2 ** 53 || $radix < 2 || $radix > 36) {
55 return ExcelError::NAN(); // Numeric range constraints
56 }
57
58 $outcome = strtoupper((string) base_convert("$number", 10, $radix));
59 if ($minLength !== null) {
60 $outcome = str_pad($outcome, (int) $minLength, '0', STR_PAD_LEFT); // String padding
61 }
62
63 return $outcome;
64 }
65
66 return ExcelError::VALUE();
67 }
68 }
69