1 | <?php |
||
14 | final class DecimalConstants |
||
15 | { |
||
16 | private static $ZERO = null; |
||
17 | private static $ONE = null; |
||
18 | private static $NEGATIVE_ONE = null; |
||
19 | |||
20 | private static $PI = null; |
||
21 | private static $EulerMascheroni = null; |
||
22 | |||
23 | private static $GoldenRatio = null; |
||
24 | |||
25 | private static $LightSpeed = null; |
||
26 | |||
27 | /** |
||
28 | * Private constructor |
||
29 | */ |
||
30 | private function __construct() |
||
34 | |||
35 | /** |
||
36 | * Private clone method |
||
37 | */ |
||
38 | private function __clone() |
||
42 | |||
43 | 37 | public static function zero() |
|
44 | { |
||
45 | 37 | if (self::$ZERO === null) { |
|
46 | 1 | self::$ZERO = Decimal::fromInteger(0); |
|
47 | 1 | } |
|
48 | 37 | return self::$ZERO; |
|
49 | } |
||
50 | |||
51 | 51 | public static function one() |
|
52 | { |
||
53 | 51 | if (self::$ONE === null) { |
|
54 | 1 | self::$ONE = Decimal::fromInteger(1); |
|
55 | 1 | } |
|
56 | 51 | return self::$ONE; |
|
57 | } |
||
58 | |||
59 | 32 | public static function negativeOne() |
|
66 | |||
67 | /** |
||
68 | * Returns the Pi number. |
||
69 | * @return Decimal |
||
70 | */ |
||
71 | 32 | public static function pi() |
|
72 | { |
||
73 | 32 | if (self::$PI === null) { |
|
74 | 1 | self::$PI = Decimal::fromString( |
|
75 | "3.14159265358979323846264338327950" |
||
76 | 1 | ); |
|
77 | 1 | } |
|
78 | 32 | return self::$PI; |
|
79 | } |
||
80 | |||
81 | /** |
||
82 | * Returns the Euler's E number. |
||
83 | * @param integer $scale |
||
84 | * @return Decimal |
||
85 | */ |
||
86 | 3 | public static function e($scale = 32) |
|
97 | |||
98 | /** |
||
99 | * Returns the Euler-Mascheroni constant. |
||
100 | * @return Decimal |
||
101 | */ |
||
102 | 1 | public static function eulerMascheroni() |
|
111 | |||
112 | /** |
||
113 | * Returns the Golden Ration, also named Phi. |
||
114 | * @return Decimal |
||
115 | */ |
||
116 | 1 | public static function goldenRatio() |
|
125 | |||
126 | /** |
||
127 | * Returns the Light of Speed measured in meters / second. |
||
128 | * @return Decimal |
||
129 | */ |
||
130 | 1 | public static function lightSpeed() |
|
137 | } |
||
138 |