01: // Copyright (c) 1997 Per M.A. Bothner.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.math;
05:
06: import java.io.*;
07:
08: /** General Cartesian Complex quantity. */
09:
10: public class CQuantity extends Quantity implements Externalizable {
11: Complex num;
12: Unit unt;
13:
14: public CQuantity(Complex num, Unit unit) {
15: this .num = num;
16: this .unt = unit;
17: }
18:
19: public CQuantity(RealNum real, RealNum imag, Unit unit) {
20: this .num = new CComplex(real, imag);
21: this .unt = unit;
22: }
23:
24: public Complex number() {
25: return num;
26: }
27:
28: public Unit unit() {
29: return unt;
30: }
31:
32: public boolean isExact() {
33: return num.isExact();
34: }
35:
36: public boolean isZero() {
37: return num.isZero();
38: }
39:
40: /**
41: * @serialData Write the complex value (using writeObject) followed
42: * by the Unit (also using writeUnit).
43: */
44:
45: public void writeExternal(ObjectOutput out) throws IOException {
46: out.writeObject(num);
47: out.writeObject(unt);
48: }
49:
50: public void readExternal(ObjectInput in) throws IOException,
51: ClassNotFoundException {
52: num = (Complex) in.readObject();
53: unt = (Unit) in.readObject();
54: }
55: }
|