KickJava   Java API By Example, From Geeks To Geeks.

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


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

11 public final class ComplexField extends Object JavaDoc implements Field {
12         public static final Complex ZERO=new Complex(0.0,0.0);
13         public static final Complex I=new Complex(0.0,1.0);
14         public static final Complex ONE=new Complex(1.0,0.0);
15         public static final Complex MINUS_ONE=new Complex(-1.0,0.0);
16         public static final Complex MINUS_I=new Complex(0.0,-1.0);
17         public static final Complex HALF=new Complex(0.5,0.0);
18         public static final Complex MINUS_HALF=new Complex(-0.5,0.0);
19         public static final Complex HALF_I=new Complex(0.0,0.5);
20         public static final Complex MINUS_HALF_I=new Complex(0.0,-0.5);
21         public static final Complex TWO=new Complex(2.0,0.0);
22         public static final Complex MINUS_TWO=new Complex(-2.0,0.0);
23         public static final Complex SQRT_HALF=new Complex(Math.sqrt(0.5),0.0);
24         public static final Complex SQRT_HALF_I=new Complex(0.0,Math.sqrt(0.5));
25         public static final Complex MINUS_SQRT_HALF_I=new Complex(0.0,-Math.sqrt(0.5));
26         public static final Complex PI=new Complex(Math.PI,0.0);
27         public static final Complex PI_I=new Complex(0.0,Math.PI);
28         public static final Complex PI_2=new Complex(Math.PI/2.0,0.0);
29         public static final Complex MINUS_PI_2=new Complex(-Math.PI/2.0,0.0);
30         public static final Complex PI_2_I=new Complex(0.0,Math.PI/2.0);
31         public static final Complex MINUS_PI_2_I=new Complex(0.0,-Math.PI/2.0);
32
33         private final static ComplexField _instance = new ComplexField();
34         /**
35         * Constructs a field of complex numbers.
36         */

37         private ComplexField() {}
38         /**
39         * Constructs a field of complex numbers.
40         * Singleton.
41         */

42         public static final ComplexField getInstance() {
43                 return _instance;
44         }
45         /**
46         * Returns the complex number zero.
47         */

48         public AbelianGroup.Member zero() {
49                 return ZERO;
50         }
51         /**
52         * Returns true if the complex number is equal to zero.
53         */

54         public boolean isZero(AbelianGroup.Member g) {
55                 return ZERO.equals(g);
56         }
57         /**
58         * Returns true if one complex number is the negative of the other.
59         */

60         public boolean isNegative(AbelianGroup.Member a,AbelianGroup.Member b) {
61                 return ZERO.equals(a.add(b));
62         }
63         /**
64         * Returns the complex number one.
65         */

66         public Ring.Member one() {
67                 return ONE;
68         }
69         /**
70         * Returns true if the complex number is equal to one.
71         */

72         public boolean isOne(Ring.Member r) {
73                 return ONE.equals(r);
74         }
75         /**
76         * Returns true if one complex number is the inverse of the other.
77         */

78         public boolean isInverse(Field.Member a, Field.Member b) {
79                 return ONE.equals(a.multiply(b));
80         }
81 }
82
83
Popular Tags