if ($op3 === null) { $op3 = self::$_scale; } if ($op3 <> 0) { $op1 = self::round($op1, $op3); $op2 = self::round($op2, $op3); } else { $op1 = ($op1 > 0) ? floor($op1) : ceil($op1); $op2 = ($op2 > 0) ? floor($op2) : ceil($op2); } if ($op1 > $op2) { return 1; } else if ($op1 < $op2) { return -1; } return 0; } public static function Scale($op1) { if ($op1 > 9) { require_once 'Zend/Locale/Math/Exception.php'; throw new Zend_Locale_Math_Exception("can not scale to precision $op1", $op1, null, null); } self::$_scale = $op1; return true; } } Zend_Locale_Math_PhpMath::disable(); // disable use of bcmath functions
$op1 = self::normalize($op1); $op2 = self::normalize($op2); if ($scale != 0) { $op1 = self::round($op1, $scale); $op2 = self::round($op2, $scale); } else { $op1 = $op1 > 0 ? floor($op1) : ceil($op1); $op2 = $op2 > 0 ? floor($op2) : ceil($op2); } if ($op1 > $op2) { return 1; } else { if ($op1 < $op2) { return -1; } } return 0; } public static function Scale($scale) { if ($scale > 9) { require_once 'Zend/Locale/Math/Exception.php'; throw new Zend_Locale_Math_Exception("can not scale to precision {$scale}", $scale, null, null); } self::$defaultScale = $scale; self::$defaultPrecision = pow(10, -$scale); return true; } } Zend_Locale_Math_PhpMath::disable(); // disable use of bcmath functions
public function testScale() { Zend_Locale_Math_PhpMath::disable(); $this->assertTrue(Zend_Locale_Math_PhpMath::Scale(3)); try { $this->assertTrue(Zend_Locale_Math_PhpMath::Scale(10)); $this->fail("exception expected"); } catch (Zend_Locale_Math_Exception $e) { // success } $this->assertEquals(1, Zend_Locale_Math_PhpMath::Comp(10.5556, 10.4444)); $this->assertTrue(Zend_Locale_Math_PhpMath::Scale(0)); $this->assertEquals(0, Zend_Locale_Math_PhpMath::Comp(10.5556, 10.4444)); }