View Javadoc

    1   package org.codehaus.groovy.runtime;
    2
    3   /***
    4    * FloatingPoint (Double and Float) NumberMath operations
    5    *
    6    * @author Steve Goetze
    7    */
    8   public class FloatingPointMath extends NumberMath {
    9
    10  	protected static FloatingPointMath instance = new FloatingPointMath();
    11
    12  	private FloatingPointMath() {}
    13
    14  	protected Number absImpl(Number number) {
    15  		return new Double(Math.abs(number.doubleValue()));
    16  	}
    17
    18  	protected Number addImpl(Number left, Number right) {
    19  		return new Double(left.doubleValue() + right.doubleValue());
    20  	}
    21
    22  	protected Number subtractImpl(Number left, Number right) {
    23  		return new Double(left.doubleValue() - right.doubleValue());
    24  	}
    25
    26  	protected Number multiplyImpl(Number left, Number right) {
    27  		return new Double(left.doubleValue() * right.doubleValue());
    28  	}
    29
    30  	protected Number divideImpl(Number left, Number right) {
    31  		return new Double(left.doubleValue() / right.doubleValue());
    32  	}
    33  	protected int compareToImpl(Number left, Number right) {
    34  		return Double.compare(left.doubleValue(), right.doubleValue());
    35  	}
    36
    37      protected Number modImpl(Number left, Number right) {
    38          return new Double(left.doubleValue() % right.doubleValue());
    39      }
    40
    41      protected Number negateImpl(Number left) {
    42          return new Double(-left.doubleValue());
    43      }
    44  }