00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 include_once( 'lib/ezmath/classes/mathhandlers/ezphpmath.php' );
00040
00041 define( 'EZ_BCMATH_DEFAULT_SCALE', 10 );
00042
00043 class eZBCMath extends eZPHPMath
00044 {
00045 function eZBCMath( $params = array () )
00046 {
00047 if( isset( $params['scale'] ) && is_numeric( $params['scale'] ) )
00048 $this->setScale( $params['scale'] );
00049 else
00050 $this->setScale( EZ_BCMATH_DEFAULT_SCALE );
00051 }
00052
00053 function scale()
00054 {
00055 return $this->Scale;
00056 }
00057
00058 function setScale( $scale )
00059 {
00060 $this->Scale = $scale;
00061 }
00062
00063 function add( $a, $b )
00064 {
00065 return ( bcadd( $a, $b, $this->Scale ) );
00066 }
00067
00068 function sub( $a, $b )
00069 {
00070 return ( bcsub( $a, $b, $this->Scale ) );
00071 }
00072
00073 function mul( $a, $b )
00074 {
00075 return ( bcmul( $a, $b, $this->Scale ) );
00076 }
00077
00078 function div( $a, $b )
00079 {
00080 return ( bcdiv( $a, $b, $this->Scale ) );
00081 }
00082
00083 function pow( $base, $exp )
00084 {
00085 return ( bcpow( $base, $exp, $this->Scale ) );
00086 }
00087
00088 function ceil( $value, $precision, $target )
00089 {
00090 $result = eZPHPMath::ceil( $value, $precision, $target );
00091 $result = rtrim( $result, '0' );
00092 $result = rtrim( $result, '.' );
00093 return $result;
00094 }
00095
00096 function floor( $value, $precision, $target )
00097 {
00098 $result = eZPHPMath::floor( $value, $precision, $target );
00099 $result = rtrim( $result, '0' );
00100 $result = rtrim( $result, '.' );
00101 return $result;
00102 }
00103
00104 function round( $value, $precision, $target )
00105 {
00106 $result = $value;
00107 $fractPart = $this->fractval( $value, $precision + 1 );
00108 if ( strlen( $fractPart ) > $precision )
00109 {
00110 $lastDigit = (int)substr( $fractPart, -1, 1 );
00111 $fractPart = substr( $fractPart, 0, $precision );
00112 if ( $lastDigit >= 5 )
00113 $fractPart = $this->add( $fractPart, 1 );
00114
00115 $fractPart = $this->div( $fractPart, $this->pow( 10, $precision ) );
00116
00117 $result = $this->add( $this->intval( $value ), $fractPart );
00118 $result = $this->adjustFractPart( $result, $precision, $target );
00119
00120 $result = rtrim( $result, '0' );
00121 $result = rtrim( $result, '.' );
00122 }
00123
00124 return $result;
00125 }
00126
00127
00128
00129 var $Scale;
00130 };
00131
00132 ?>