KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > maths > fields > RealField


1 package JSci.maths.fields;
2
3 import JSci.maths.*;
4 import JSci.maths.groups.AbelianGroup;
5
6 /**
7 * The RealField class encapsulates the field of real numbers.
8 * @version 1.0
9 * @author Mark Hale
10 */

11 public final class RealField extends Object JavaDoc implements Field {
12         public final static MathDouble ZERO=new MathDouble(0.0);
13         public final static MathDouble ONE=new MathDouble(1.0);
14         public final static MathDouble PI=new MathDouble(Math.PI);
15         public final static MathDouble E=new MathDouble(Math.E);
16         public final static MathDouble GAMMA=new MathDouble(NumericalConstants.GAMMA);
17         public final static MathDouble INFINITY=new MathDouble(Double.POSITIVE_INFINITY);
18         public final static MathDouble NaN=new MathDouble(Double.NaN);
19
20         private final static RealField _instance = new RealField();
21         /**
22         * Constructs a field of real numbers.
23         */

24         private RealField() {}
25         /**
26         * Constructs a field of real numbers.
27         * Singleton.
28         */

29         public static final RealField getInstance() {
30                 return _instance;
31         }
32         /**
33         * Returns the real number zero.
34         */

35         public AbelianGroup.Member zero() {
36                 return ZERO;
37         }
38         /**
39         * Returns true if the real number is equal to zero.
40         */

41         public boolean isZero(AbelianGroup.Member g) {
42                 return ZERO.equals(g);
43         }
44         /**
45         * Returns true if one real number is the negative of the other.
46         */

47         public boolean isNegative(AbelianGroup.Member a, AbelianGroup.Member b) {
48                 return ZERO.equals(a.add(b));
49         }
50         /**
51         * Returns the real number one.
52         */

53         public Ring.Member one() {
54                 return ONE;
55         }
56         /**
57         * Returns true if the real number is equal to one.
58         */

59         public boolean isOne(Ring.Member r) {
60                 return ONE.equals(r);
61         }
62         /**
63         * Returns true if one real number is the inverse of the other.
64         */

65         public boolean isInverse(Field.Member a, Field.Member b) {
66                 return ONE.equals(a.multiply(b));
67         }
68 }
69
70
Popular Tags