JML

org.jmlspecs.samples.dbc
Class Polar

java.lang.Object
  extended byorg.jmlspecs.samples.dbc.ComplexOps
      extended byorg.jmlspecs.samples.dbc.Polar
All Implemented Interfaces:
Complex

public strictfp class Polar
extends ComplexOps

Complex numbers in polar coordinates.

Author:
Gary T. Leavens with help from Abelson and Sussman's Structure and Interpretation of Computer Programs

Field Summary
private  double ang
          The angle of this number.
private  double mag
          The magnitude of this number.
 
Constructor Summary
Polar(double mag, double ang)
          Initialize this polar coordinate number with magnitude mag and angle ang, except that when the magnitude is negative, this is interpreted as magnitude -mag and angle ang+StrictMath.PI.
 
Method Summary
 double angle()
          Return the angle of this complex number.
 double imaginaryPart()
          Return the imaginary part of this complex number.
 double magnitude()
          Return the magnitude of this complex number.
 double realPart()
          Return the real part of this complex number.
static double standardizeAngle(double rad)
          Standardize the angle so it's between -StrictMath.PI and StrictMath.PI (radians).
 String toString()
           
 
Methods inherited from class org.jmlspecs.samples.dbc.ComplexOps
add, div, equals, hashCode, mul, sub
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

mag

private double mag
The magnitude of this number.


ang

private double ang
The angle of this number.

Constructor Detail

Polar

public Polar(double mag,
             double ang)
      throws IllegalArgumentException
Initialize this polar coordinate number with magnitude mag and angle ang, except that when the magnitude is negative, this is interpreted as magnitude -mag and angle ang+StrictMath.PI.

Parameters:
mag - the magnitude desired
ang - the angle in radians, measured counterclockwise from the positive x axis
Throws:
IllegalArgumentException
Method Detail

standardizeAngle

public static double standardizeAngle(double rad)
                               throws IllegalArgumentException
Standardize the angle so it's between -StrictMath.PI and StrictMath.PI (radians).

Throws:
IllegalArgumentException

realPart

public double realPart()
Description copied from interface: Complex
Return the real part of this complex number.


imaginaryPart

public double imaginaryPart()
Description copied from interface: Complex
Return the imaginary part of this complex number.


magnitude

public double magnitude()
Description copied from interface: Complex
Return the magnitude of this complex number.


angle

public double angle()
Description copied from interface: Complex
Return the angle of this complex number.


toString

public String toString()
Overrides:
toString in class Object

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.