Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Static Public Member Functions | Static Public Attributes
Zend_Locale_Math_PhpMath Class Reference
Inheritance diagram for Zend_Locale_Math_PhpMath:
Zend_Locale_Math

Static Public Member Functions

static disable ()
 
static Add ($op1, $op2, $scale=null)
 
static Sub ($op1, $op2, $scale=null)
 
static Pow ($op1, $op2, $scale=null)
 
static Mul ($op1, $op2, $scale=null)
 
static Div ($op1, $op2, $scale=null)
 
static Sqrt ($op1, $scale=null)
 
static Mod ($op1, $op2)
 
static Comp ($op1, $op2, $scale=null)
 
static Scale ($scale)
 
- Static Public Member Functions inherited from Zend_Locale_Math
static isBcmathDisabled ()
 
static round ($op1, $precision=0)
 
static floatalize ($value)
 
static normalize ($value)
 
static localize ($value)
 
static exponent ($value, $scale=null)
 
static Add ($op1, $op2, $scale=null)
 
static Sub ($op1, $op2, $scale=null)
 
static Pow ($op1, $op2, $scale=null)
 
static Mul ($op1, $op2, $scale=null)
 
static Div ($op1, $op2, $scale=null)
 
static Sqrt ($op1, $scale=null)
 
static Mod ($op1, $op2)
 
static Comp ($op1, $op2, $scale=null)
 

Static Public Attributes

static $defaultScale
 
static $defaultPrecision
 
- Static Public Attributes inherited from Zend_Locale_Math
static $_bcmathDisabled = false
 
static $add = array('Zend_Locale_Math', 'Add')
 
static $sub = array('Zend_Locale_Math', 'Sub')
 
static $pow = array('Zend_Locale_Math', 'Pow')
 
static $mul = array('Zend_Locale_Math', 'Mul')
 
static $div = array('Zend_Locale_Math', 'Div')
 
static $comp = array('Zend_Locale_Math', 'Comp')
 
static $sqrt = array('Zend_Locale_Math', 'Sqrt')
 
static $mod = array('Zend_Locale_Math', 'Mod')
 
static $scale = 'bcscale'
 

Detailed Description

Definition at line 34 of file PhpMath.php.

Member Function Documentation

◆ Add()

static Add (   $op1,
  $op2,
  $scale = null 
)
static

Definition at line 57 of file PhpMath.php.

58  {
59  if ($scale === null) {
62  } else {
63  $precision = pow(10, -$scale);
64  }
65 
66  if (empty($op1)) {
67  $op1 = 0;
68  }
69  $op1 = self::normalize($op1);
70  $op2 = self::normalize($op2);
71  $result = $op1 + $op2;
72  if (is_infinite($result) or (abs($result - $op2 - $op1) > $precision)) {
73  #require_once 'Zend/Locale/Math/Exception.php';
74  throw new Zend_Locale_Math_Exception("addition overflow: $op1 + $op2 != $result", $op1, $op2, $result);
75  }
76 
77  return self::round(self::normalize($result), $scale);
78  }
static $scale
Definition: Math.php:48
static normalize($value)
Definition: Math.php:174
static round($op1, $precision=0)
Definition: Math.php:65

◆ Comp()

static Comp (   $op1,
  $op2,
  $scale = null 
)
static

Definition at line 209 of file PhpMath.php.

210  {
211  if ($scale === null) {
213  }
214 
215  if (empty($op1)) {
216  $op1 = 0;
217  }
218  $op1 = self::normalize($op1);
219  $op2 = self::normalize($op2);
220  if ($scale <> 0) {
221  $op1 = self::round($op1, $scale);
222  $op2 = self::round($op2, $scale);
223  } else {
224  $op1 = ($op1 > 0) ? floor($op1) : ceil($op1);
225  $op2 = ($op2 > 0) ? floor($op2) : ceil($op2);
226  }
227  if ($op1 > $op2) {
228  return 1;
229  } else if ($op1 < $op2) {
230  return -1;
231  }
232  return 0;
233  }
static $scale
Definition: Math.php:48
static normalize($value)
Definition: Math.php:174
static round($op1, $precision=0)
Definition: Math.php:65

◆ disable()

static disable ( )
static

Definition at line 36 of file PhpMath.php.

37  {
38  self::$_bcmathDisabled = true;
39  self::$add = array('Zend_Locale_Math_PhpMath', 'Add');
40  self::$sub = array('Zend_Locale_Math_PhpMath', 'Sub');
41  self::$pow = array('Zend_Locale_Math_PhpMath', 'Pow');
42  self::$mul = array('Zend_Locale_Math_PhpMath', 'Mul');
43  self::$div = array('Zend_Locale_Math_PhpMath', 'Div');
44  self::$comp = array('Zend_Locale_Math_PhpMath', 'Comp');
45  self::$sqrt = array('Zend_Locale_Math_PhpMath', 'Sqrt');
46  self::$mod = array('Zend_Locale_Math_PhpMath', 'Mod');
47  self::$scale = array('Zend_Locale_Math_PhpMath', 'Scale');
48 
49  self::$defaultScale = 0;
50  self::$defaultPrecision = 1;
51  }

◆ Div()

static Div (   $op1,
  $op2,
  $scale = null 
)
static

Definition at line 145 of file PhpMath.php.

146  {
147  if ($scale === null) {
149  }
150 
151  if (empty($op2)) {
152  #require_once 'Zend/Locale/Math/Exception.php';
153  throw new Zend_Locale_Math_Exception("can not divide by zero", $op1, $op2, null);
154  }
155  if (empty($op1)) {
156  $op1 = 0;
157  }
158  $op1 = self::normalize($op1);
159  $op2 = self::normalize($op2);
160  $result = $op1 / $op2;
161  if (is_infinite($result) or is_nan($result)) {
162  #require_once 'Zend/Locale/Math/Exception.php';
163  throw new Zend_Locale_Math_Exception("division overflow: $op1 / $op2 != $result", $op1, $op2, $result);
164  }
165 
166  return self::round(self::normalize($result), $scale);
167  }
static $scale
Definition: Math.php:48
static normalize($value)
Definition: Math.php:174
static round($op1, $precision=0)
Definition: Math.php:65

◆ Mod()

static Mod (   $op1,
  $op2 
)
static

Definition at line 187 of file PhpMath.php.

188  {
189  if (empty($op1)) {
190  $op1 = 0;
191  }
192  if (empty($op2)) {
193  return NULL;
194  }
195  $op1 = self::normalize($op1);
196  $op2 = self::normalize($op2);
197  if ((int)$op2 == 0) {
198  return NULL;
199  }
200  $result = $op1 % $op2;
201  if (is_nan($result) or (($op1 - $result) % $op2 != 0)) {
202  #require_once 'Zend/Locale/Math/Exception.php';
203  throw new Zend_Locale_Math_Exception("modulus calculation error: $op1 % $op2 != $result", $op1, $op2, $result);
204  }
205 
206  return self::normalize($result);
207  }
static normalize($value)
Definition: Math.php:174

◆ Mul()

static Mul (   $op1,
  $op2,
  $scale = null 
)
static

Definition at line 125 of file PhpMath.php.

126  {
127  if ($scale === null) {
129  }
130 
131  if (empty($op1)) {
132  $op1 = 0;
133  }
134  $op1 = self::normalize($op1);
135  $op2 = self::normalize($op2);
136  $result = $op1 * $op2;
137  if (is_infinite($result) or is_nan($result)) {
138  #require_once 'Zend/Locale/Math/Exception.php';
139  throw new Zend_Locale_Math_Exception("multiplication overflow: $op1 * $op2 != $result", $op1, $op2, $result);
140  }
141 
142  return self::round(self::normalize($result), $scale);
143  }
static $scale
Definition: Math.php:48
static normalize($value)
Definition: Math.php:174
static round($op1, $precision=0)
Definition: Math.php:65

◆ Pow()

static Pow (   $op1,
  $op2,
  $scale = null 
)
static

Definition at line 103 of file PhpMath.php.

104  {
105  if ($scale === null) {
107  }
108 
109  $op1 = self::normalize($op1);
110  $op2 = self::normalize($op2);
111 
112  // BCMath extension doesn't use decimal part of the power
113  // Provide the same behavior
114  $op2 = ($op2 > 0) ? floor($op2) : ceil($op2);
115 
116  $result = pow($op1, $op2);
117  if (is_infinite($result) or is_nan($result)) {
118  #require_once 'Zend/Locale/Math/Exception.php';
119  throw new Zend_Locale_Math_Exception("power overflow: $op1 ^ $op2", $op1, $op2, $result);
120  }
121 
122  return self::round(self::normalize($result), $scale);
123  }
static $scale
Definition: Math.php:48
static normalize($value)
Definition: Math.php:174
static round($op1, $precision=0)
Definition: Math.php:65

◆ Scale()

static Scale (   $scale)
static

Definition at line 235 of file PhpMath.php.

236  {
237  if ($scale > 9) {
238  #require_once 'Zend/Locale/Math/Exception.php';
239  throw new Zend_Locale_Math_Exception("can not scale to precision $scale", $scale, null, null);
240  }
241  self::$defaultScale = $scale;
242  self::$defaultPrecision = pow(10, -$scale);
243  return true;
244  }
static $scale
Definition: Math.php:48

◆ Sqrt()

static Sqrt (   $op1,
  $scale = null 
)
static

Definition at line 169 of file PhpMath.php.

170  {
171  if ($scale === null) {
173  }
174 
175  if (empty($op1)) {
176  $op1 = 0;
177  }
178  $op1 = self::normalize($op1);
179  $result = sqrt($op1);
180  if (is_nan($result)) {
181  return NULL;
182  }
183 
184  return self::round(self::normalize($result), $scale);
185  }
static $scale
Definition: Math.php:48
static normalize($value)
Definition: Math.php:174
static round($op1, $precision=0)
Definition: Math.php:65

◆ Sub()

static Sub (   $op1,
  $op2,
  $scale = null 
)
static

Definition at line 80 of file PhpMath.php.

81  {
82  if ($scale === null) {
85  } else {
86  $precision = pow(10, -$scale);
87  }
88 
89  if (empty($op1)) {
90  $op1 = 0;
91  }
92  $op1 = self::normalize($op1);
93  $op2 = self::normalize($op2);
94  $result = $op1 - $op2;
95  if (is_infinite($result) or (abs($result + $op2 - $op1) > $precision)) {
96  #require_once 'Zend/Locale/Math/Exception.php';
97  throw new Zend_Locale_Math_Exception("subtraction overflow: $op1 - $op2 != $result", $op1, $op2, $result);
98  }
99 
100  return self::round(self::normalize($result), $scale);
101  }
static $scale
Definition: Math.php:48
static normalize($value)
Definition: Math.php:174
static round($op1, $precision=0)
Definition: Math.php:65

Field Documentation

◆ $defaultPrecision

$defaultPrecision
static

Definition at line 54 of file PhpMath.php.

◆ $defaultScale

$defaultScale
static

Definition at line 53 of file PhpMath.php.


The documentation for this class was generated from the following file: