JML

org.jmlspecs.samples.dbc
Class ComplexOps

java.lang.Object
  extended byorg.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

Class Specifications

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);

Model Field Summary
 
Model fields inherited from class java.lang.Object
_getClass, objectState, theString
 
Ghost Field Summary
 
Ghost fields inherited from class java.lang.Object
objectTimesFinalized, owner
 
Ghost fields inherited from interface org.jmlspecs.samples.dbc.Complex
tolerance
 
Constructor Summary
ComplexOps()
           
 
Model Method Summary
 
Model methods inherited from class java.lang.Object
hashValue
 
Model methods inherited from interface org.jmlspecs.samples.dbc.Complex
positiveRemainder, similarAngle
 
Method Summary
 Complex add(Complex b)
          Return this + b (the sum of this and b).
 Complex div(Complex b)
          Return this/b (the quotient of this by b).
 boolean equals(nullable Object o)
          Return true if these are the same complex number.
 int hashCode()
          Return a hashCode for this number.
 Complex mul(Complex b)
          Return this * b (the product of this and b).
 Complex sub(Complex b)
          Return this - b (the difference between this and b).
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jmlspecs.samples.dbc.Complex
angle, imaginaryPart, magnitude, realPart
 

Constructor Detail

ComplexOps

public ComplexOps()
Method Detail

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

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.