org.jmlspecs.samples.dbc
Class ComplexOps
java.lang.Object
org.jmlspecs.samples.dbc.ComplexOps
- All Implemented Interfaces:
- Complex
- Direct Known Subclasses:
- Polar, Rectangular
- public abstract strictfp class ComplexOps
- extends Object
- implements Complex
An abstract class that holds all of the common algorithms for
complex numbers. Note that this class knows about both of its subclasses
Rectangular and Polar.
- Author:
- Gary T. Leavens with help from Abelson and Sussman's
Structure and Interpretation of Computer Programs
Specifications inherited from class Object |
represents objectState <- org.jmlspecs.lang.JMLDataGroup.IT;
public represents _getClass <- \typeof(this); |
Specifications inherited from interface Complex |
axiom ( \forall double d, dd; dd > 0.0; d%dd > -dd&&d%dd < dd);
axiom ( \forall double d, dd; ; d > -dd ==> d+dd > 0.0); |
Ghost fields inherited from interface org.jmlspecs.samples.dbc.Complex |
tolerance |
ComplexOps
public ComplexOps()
add
public Complex add(Complex b)
- Description copied from interface:
Complex
- Return this + b (the sum of this and b).
- Specified by:
add
in interface Complex
- Specifications: (class)pure
- Specifications inherited from overridden method add(Complex b) in interface Complex:
(class)pure -
requires_redundantly b != null;
ensures_redundantly \result != null;
ensures org.jmlspecs.models.JMLDouble.approximatelyEqualTo(this.realPart()+b.realPart(),\result .realPart(),0.0050);
ensures org.jmlspecs.models.JMLDouble.approximatelyEqualTo(this.imaginaryPart()+b.imaginaryPart(),\result .imaginaryPart(),0.0050);
sub
public Complex sub(Complex b)
- Description copied from interface:
Complex
- Return this - b (the difference between this and b).
- Specified by:
sub
in interface Complex
- Specifications: (class)pure
- Specifications inherited from overridden method sub(Complex b) in interface Complex:
(class)pure -
requires_redundantly b != null;
ensures_redundantly \result != null;
ensures org.jmlspecs.models.JMLDouble.approximatelyEqualTo(this.realPart()-b.realPart(),\result .realPart(),0.0050);
ensures org.jmlspecs.models.JMLDouble.approximatelyEqualTo(this.imaginaryPart()-b.imaginaryPart(),\result .imaginaryPart(),0.0050);
mul
public Complex mul(Complex b)
- Description copied from interface:
Complex
- Return this * b (the product of this and b).
- Specified by:
mul
in interface Complex
- Specifications: (class)pure
- Specifications inherited from overridden method mul(Complex b) in interface Complex:
(class)pure -
requires_redundantly b != null;
requires !java.lang.Double.isNaN(this.magnitude()*b.magnitude());
requires !java.lang.Double.isNaN(this.angle())&&!java.lang.Double.isNaN(b.angle());
ensures_redundantly \result != null;
ensures org.jmlspecs.models.JMLDouble.approximatelyEqualTo(this.magnitude()*b.magnitude(),\result .magnitude(),0.0050);
ensures this.similarAngle(this.angle()+b.angle(),\result .angle());
- also
-
requires_redundantly b != null;
requires java.lang.Double.isNaN(this.magnitude()*b.magnitude())||java.lang.Double.isNaN(this.angle())||java.lang.Double.isNaN(b.angle());
ensures java.lang.Double.isNaN(\result .realPart());
ensures \result .imaginaryPart() == 0.0;
div
public Complex div(Complex b)
- Description copied from interface:
Complex
- Return this/b (the quotient of this by b).
- Specified by:
div
in interface Complex
- Specifications: (class)pure
- Specifications inherited from overridden method div(Complex b) in interface Complex:
(class)pure -
requires_redundantly b != null;
requires !java.lang.Double.isNaN(this.magnitude()/b.magnitude());
requires !java.lang.Double.isNaN(this.angle())&&!java.lang.Double.isNaN(b.angle());
ensures_redundantly \result != null;
ensures org.jmlspecs.models.JMLDouble.approximatelyEqualTo(this.magnitude()/b.magnitude(),\result .magnitude(),0.0050);
ensures this.similarAngle(this.angle()-b.angle(),\result .angle());
- also
-
requires_redundantly b != null;
requires java.lang.Double.isNaN(this.magnitude()/b.magnitude())||java.lang.Double.isNaN(this.angle())||java.lang.Double.isNaN(b.angle());
ensures java.lang.Double.isNaN(\result .realPart());
ensures \result .imaginaryPart() == 0.0;
equals
public boolean equals(nullable Object o)
- Description copied from interface:
Complex
- Return true if these are the same complex number.
- Specified by:
equals
in interface Complex
- Overrides:
equals
in class Object
- Specifications: (class)pure
- Specifications inherited from overridden method equals(Object obj) in class Object:
pure -
public normal_behavior
requires obj != null;
ensures (* \result is true when obj is "equal to" this object *);
- also
-
public normal_behavior
requires this == obj;
ensures \result ;
- also
-
public code normal_behavior
requires obj != null;
ensures \result <==> this == obj;
- also
-
diverges false;
ensures obj == null ==> !\result ;
- Specifications inherited from overridden method equals(Object o) in interface Complex:
(class)pure- also
-
ensures \result <==> o instanceof org.jmlspecs.samples.dbc.Complex&&this.realPart() == ((org.jmlspecs.samples.dbc.Complex)o).realPart()&&this.imaginaryPart() == ((org.jmlspecs.samples.dbc.Complex)o).imaginaryPart();
ensures \result <==> o instanceof org.jmlspecs.samples.dbc.Complex&&this.magnitude() == ((org.jmlspecs.samples.dbc.Complex)o).magnitude()&&this.angle() == ((org.jmlspecs.samples.dbc.Complex)o).angle();
hashCode
public int hashCode()
- Description copied from interface:
Complex
- Return a hashCode for this number.
- Specified by:
hashCode
in interface Complex
- Overrides:
hashCode
in class Object
- Specifications: (class)pure
- Specifications inherited from overridden method in class Object:
-
public behavior
assignable objectState;
ensures (* \result is a hash code for this object *);
- also
-
public code normal_behavior
assignable \nothing;
- Specifications inherited from overridden method in interface Complex:
(class)pure
JML is Copyright (C) 1998-2002 by Iowa State University and is distributed under the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This release depends on code from the MultiJava project and is based in part on the Kopi project Copyright (C) 1990-99 DMS Decision Management Systems Ges.m.b.H.