01: package JSci.maths.fields;
02:
03: import JSci.maths.*;
04: import JSci.maths.groups.AbelianGroup;
05:
06: /**
07: * The RealField class encapsulates the field of real numbers.
08: * @version 1.0
09: * @author Mark Hale
10: */
11: public final class RealField extends Object 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(
17: NumericalConstants.GAMMA);
18: public final static MathDouble INFINITY = new MathDouble(
19: Double.POSITIVE_INFINITY);
20: public final static MathDouble NaN = new MathDouble(Double.NaN);
21:
22: private final static RealField _instance = new RealField();
23:
24: /**
25: * Constructs a field of real numbers.
26: */
27: private RealField() {
28: }
29:
30: /**
31: * Constructs a field of real numbers.
32: * Singleton.
33: */
34: public static final RealField getInstance() {
35: return _instance;
36: }
37:
38: /**
39: * Returns the real number zero.
40: */
41: public AbelianGroup.Member zero() {
42: return ZERO;
43: }
44:
45: /**
46: * Returns true if the real number is equal to zero.
47: */
48: public boolean isZero(AbelianGroup.Member g) {
49: return ZERO.equals(g);
50: }
51:
52: /**
53: * Returns true if one real number is the negative of the other.
54: */
55: public boolean isNegative(AbelianGroup.Member a,
56: AbelianGroup.Member b) {
57: return ZERO.equals(a.add(b));
58: }
59:
60: /**
61: * Returns the real number one.
62: */
63: public Ring.Member one() {
64: return ONE;
65: }
66:
67: /**
68: * Returns true if the real number is equal to one.
69: */
70: public boolean isOne(Ring.Member r) {
71: return ONE.equals(r);
72: }
73:
74: /**
75: * Returns true if one real number is the inverse of the other.
76: */
77: public boolean isInverse(Field.Member a, Field.Member b) {
78: return ONE.equals(a.multiply(b));
79: }
80: }
|