KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lsmp > djep > groupJep > groups > Reals


1 /* @author rich
2  * Created on 05-Mar-2004
3  *
4  * This code is covered by a Creative Commons
5  * Attribution, Non Commercial, Share Alike license
6  * <a HREF="http://creativecommons.org/licenses/by-nc-sa/1.0">License</a>
7  */

8 package org.lsmp.djep.groupJep.groups;
9 import org.lsmp.djep.groupJep.interfaces.*;
10
11 /**
12  * @author Rich Morris
13  * Created on 05-Mar-2004
14  */

15 public class Reals extends Group implements FieldI,OrderedSetI,HasPowerI {
16
17     private Double JavaDoc ZERO = new Double JavaDoc(0.0);
18     private Double JavaDoc ONE = new Double JavaDoc(1.0);
19
20     /**
21      * Operations on the reals (Implemented as Doubles
22      */

23     public Reals() {
24     }
25
26     public Number JavaDoc getZERO() {
27         return ZERO;
28     }
29
30     public Number JavaDoc getONE() {
31         return ONE;
32     }
33
34     public Number JavaDoc getInverse(Number JavaDoc num) {
35         return new Double JavaDoc(1.0/num.doubleValue());
36     }
37
38     public Number JavaDoc getMulInverse(Number JavaDoc num) {
39         return new Double JavaDoc(1.0 / num.doubleValue());
40     }
41
42     public Number JavaDoc add(Number JavaDoc a, Number JavaDoc b) {
43         return new Double JavaDoc(a.doubleValue()+b.doubleValue());
44     }
45
46     public Number JavaDoc sub(Number JavaDoc a, Number JavaDoc b) {
47         return new Double JavaDoc(a.doubleValue()-b.doubleValue());
48     }
49
50     public Number JavaDoc mul(Number JavaDoc a, Number JavaDoc b) {
51         return new Double JavaDoc(a.doubleValue()*b.doubleValue());
52     }
53
54     public Number JavaDoc div(Number JavaDoc a, Number JavaDoc b) {
55         return new Double JavaDoc(a.doubleValue()/b.doubleValue());
56     }
57
58     public Number JavaDoc pow(Number JavaDoc a, Number JavaDoc b) {
59         return new Double JavaDoc(Math.pow(a.doubleValue(),b.doubleValue()));
60     }
61
62     public Number JavaDoc valueOf(String JavaDoc str) {
63         return new Double JavaDoc(str);
64     }
65
66     public boolean equals(Number JavaDoc a,Number JavaDoc b) {
67         return ((Double JavaDoc) a).compareTo((Double JavaDoc) b) == 0;
68     }
69     
70     public int compare(Number JavaDoc a,Number JavaDoc b) {
71         return ((Double JavaDoc) a).compareTo((Double JavaDoc) b);
72     }
73 }
74
Popular Tags