Clover coverage report - groovy - 1.0-beta-6
Coverage timestamp: Thu Jul 15 2004 13:18:22 BST
file stats: LOC: 66   Methods: 9
NCLOC: 40   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
BigDecimalMath.java - 0% 0% 0%
coverage
 1   
 package org.codehaus.groovy.runtime;
 2   
 
 3   
 import java.math.BigDecimal;
 4   
 
 5   
 /**
 6   
  * BigDecimal NumberMath operations
 7   
  * 
 8   
  * @author Steve Goetze
 9   
  */
 10   
 public class BigDecimalMath extends NumberMath {
 11   
 
 12   
     //This is an arbitrary value, picked as a reasonable choice for a rounding point
 13   
     //for typical user math.
 14   
     public static final int MAX_DIVISION_SCALE = 10;
 15   
     
 16   
     protected static BigDecimalMath instance = new BigDecimalMath();
 17   
     
 18  0
     private BigDecimalMath() {}
 19   
 
 20  0
     protected Number absImpl(Number number) {
 21  0
         return toBigDecimal(number).abs();
 22   
     }
 23   
     
 24  0
     protected Number addImpl(Number left, Number right) {
 25  0
         return toBigDecimal(left).add(toBigDecimal(right));
 26   
     }
 27   
 
 28  0
     protected Number subtractImpl(Number left, Number right) {
 29  0
         return toBigDecimal(left).subtract(toBigDecimal(right));
 30   
     }
 31   
 
 32  0
     protected Number multiplyImpl(Number left, Number right) {
 33  0
         return toBigDecimal(left).multiply(toBigDecimal(right));
 34   
     }
 35   
 
 36  0
     protected Number divideImpl(Number left, Number right) {
 37   
         //Hack until Java 1.5 BigDecimal is available.  For now, pick
 38   
         //a result scale which is the maximum of the scale of the
 39   
         //two operands and an arbitrary maximum (similar to what a
 40   
         //handheld calculator would do).  Then, normalize the result
 41   
         //by removing any trailing zeros.
 42  0
         BigDecimal bigLeft = toBigDecimal(left);
 43  0
         BigDecimal bigRight = toBigDecimal(right);
 44  0
         int scale = Math.max(bigLeft.scale(), bigRight.scale());
 45  0
         return normalize(bigLeft.divide(bigRight, Math.max(scale, MAX_DIVISION_SCALE), BigDecimal.ROUND_HALF_UP));
 46   
     }
 47   
     
 48  0
     protected int compareToImpl(Number left, Number right) {
 49  0
         return toBigDecimal(left).compareTo(toBigDecimal(right));
 50   
     }
 51   
     
 52  0
     private BigDecimal normalize(BigDecimal number) {
 53  0
         try {
 54  0
             while (true) {
 55  0
                 number = number.setScale(number.scale()-1);
 56   
             } 
 57   
         } catch (ArithmeticException e) {
 58  0
             return number;
 59   
         }
 60   
     }
 61   
 
 62  0
     protected Number negateImpl(Number left) {
 63  0
         return toBigDecimal(left).negate();
 64   
     }
 65   
 }
 66