[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZBCMath class 4 // 5 // Created on: <04-Nov-2005 12:26:52 dl> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! \file ezbcmath.php 30 */ 31 32 /*! 33 \class eZBCMath ezbcmath.php 34 \brief Handles calculation using bcmath library. 35 */ 36 37 include_once ( 'lib/ezmath/classes/mathhandlers/ezphpmath.php' ); 38 39 define( 'EZ_BCMATH_DEFAULT_SCALE', 10 ); 40 41 class eZBCMath extends eZPHPMath 42 { 43 function eZBCMath( $params = array () ) 44 { 45 if( isset( $params['scale'] ) && is_numeric( $params['scale'] ) ) 46 $this->setScale( $params['scale'] ); 47 else 48 $this->setScale( EZ_BCMATH_DEFAULT_SCALE ); 49 } 50 51 function scale() 52 { 53 return $this->Scale; 54 } 55 56 function setScale( $scale ) 57 { 58 $this->Scale = $scale; 59 } 60 61 function add( $a, $b ) 62 { 63 return ( bcadd( $a, $b, $this->Scale ) ); 64 } 65 66 function sub( $a, $b ) 67 { 68 return ( bcsub( $a, $b, $this->Scale ) ); 69 } 70 71 function mul( $a, $b ) 72 { 73 return ( bcmul( $a, $b, $this->Scale ) ); 74 } 75 76 function div( $a, $b ) 77 { 78 return ( bcdiv( $a, $b, $this->Scale ) ); 79 } 80 81 function pow( $base, $exp ) 82 { 83 return ( bcpow( $base, $exp, $this->Scale ) ); 84 } 85 86 function ceil( $value, $precision, $target ) 87 { 88 $result = eZPHPMath::ceil( $value, $precision, $target ); 89 $result = rtrim( $result, '0' ); 90 $result = rtrim( $result, '.' ); 91 return $result; 92 } 93 94 function floor( $value, $precision, $target ) 95 { 96 $result = eZPHPMath::floor( $value, $precision, $target ); 97 $result = rtrim( $result, '0' ); 98 $result = rtrim( $result, '.' ); 99 return $result; 100 } 101 102 function round( $value, $precision, $target ) 103 { 104 $result = $value; 105 $fractPart = $this->fractval( $value, $precision + 1 ); 106 if ( strlen( $fractPart ) > $precision ) 107 { 108 $lastDigit = (int)substr( $fractPart, -1, 1 ); 109 $fractPart = substr( $fractPart, 0, $precision ); 110 if ( $lastDigit >= 5 ) 111 $fractPart = $this->add( $fractPart, 1 ); 112 113 $fractPart = $this->div( $fractPart, $this->pow( 10, $precision ) ); 114 115 $result = $this->add( $this->intval( $value ), $fractPart ); 116 $result = $this->adjustFractPart( $result, $precision, $target ); 117 118 $result = rtrim( $result, '0' ); 119 $result = rtrim( $result, '.' ); 120 } 121 122 return $result; 123 } 124 125 126 /// \privatesection 127 var $Scale; 128 }; 129 130 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |