KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > groovy > runtime > FloatingPointMath


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 JavaDoc absImpl(Number JavaDoc number) {
15         return new Double JavaDoc(Math.abs(number.doubleValue()));
16     }
17     
18     protected Number JavaDoc addImpl(Number JavaDoc left, Number JavaDoc right) {
19         return new Double JavaDoc(left.doubleValue() + right.doubleValue());
20     }
21
22     protected Number JavaDoc subtractImpl(Number JavaDoc left, Number JavaDoc right) {
23         return new Double JavaDoc(left.doubleValue() - right.doubleValue());
24     }
25
26     protected Number JavaDoc multiplyImpl(Number JavaDoc left, Number JavaDoc right) {
27         return new Double JavaDoc(left.doubleValue() * right.doubleValue());
28     }
29
30     protected Number JavaDoc divideImpl(Number JavaDoc left, Number JavaDoc right) {
31         return new Double JavaDoc(left.doubleValue() / right.doubleValue());
32     }
33     protected int compareToImpl(Number JavaDoc left, Number JavaDoc right) {
34         return Double.compare(left.doubleValue(), right.doubleValue());
35     }
36     
37     protected Number JavaDoc modImpl(Number JavaDoc left, Number JavaDoc right) {
38         return new Double JavaDoc(left.doubleValue() % right.doubleValue());
39     }
40     
41     protected Number JavaDoc negateImpl(Number JavaDoc left) {
42         return new Double JavaDoc(-left.doubleValue());
43     }
44 }
45
Popular Tags