Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes

jscicalc.complex.DoubleFormat Class Reference

Collaboration diagram for jscicalc.complex.DoubleFormat:
Collaboration graph
[legend]

List of all members.

Classes

class  HTMLStringRepresentation
 Inner class used to represent HTML string representations of doubles. More...

Public Member Functions

 DoubleFormat (double number, Base base)
 Constructor.
void setPrecision (int precision)
 Set the precision.
void setBase (final Base base)
 Set the base.
void setNotation (Notation notation)
 Set the notation.
HTMLStringRepresentation representation ()
 Produce a string representing the number in current Notation and precision.
HTMLStringRepresentation scientific ()
 Produce a string representing the number using scientific notation.
double getNumber ()
 Get method for finding the number stored in this object.
double getAbsNumber ()
 Get method for finding the absolute value of the number stored in this object.
String getEString ()
 Exponents are represented as superscripts with a prefix, which may depend on the Base.
int getEStringLength ()
 Exponents are represented as superscripts with a prefix, which may depend on the Base.

Static Public Member Functions

static int midDigit (Base base)
 This is used during rounding.
static int baseInt (Base base)
 This is used during rounding.
static void main (String[] args)
 Standard test function.

Public Attributes

final HTMLStringRepresentation NullRepresentation
 This is used to assign HTMLStringRepresentation objects to a null value.

Static Public Attributes

static final long BIAS = 1023
 Standard constant for IEEE 754 doubles.
static final long E_MAX = 1023
 Standard constant for IEEE 754 doubles.
static final long E_MIN = -1022
 Standard constant for IEEE 754 doubles.
static final java.util.Vector
< String > 
basePoint = new java.util.Vector<String>( java.util.Arrays.asList( "." ) )
 This is how we represent a base point in output strings.
static final String startExponent = "<sup style=\"font-size:60%;\">"
 This is how we represent the start of an exponent in output strings.
static final String endExponent = "</sup>"
 This is how we represent the end of an exponent in output strings.
static final java.util.Vector
< String > 
minus = new java.util.Vector<String>( java.util.Arrays.asList( "&#8722;" ) )
 This is how we represent a minus sign in output strings.
static final java.util.Vector
< String > 
NaN = new java.util.Vector<String>( java.util.Arrays.asList( "N", "a", "N" ) )
 This is how we represent a NaN (not a number) in output strings.
static final java.util.Vector
< String > 
infinity = new java.util.Vector<String>( java.util.Arrays.asList( "&#8734;" ) )
 This is how we represent the number infinity in output strings.
static final java.util.Vector
< String > 
minusInfinity = new java.util.Vector<String>( java.util.Arrays.asList( "&#8722;", "&#8734;" ) )
 This is how we represent the number negative infinity in output strings.
static final String startHTML = "<html>"
 This is how we represent the start of HTML in output strings.
static final String endHTML = "</html>"
 This is how we represent the end of HTML in output strings.
static final java.util.Vector
< String > 
imPrefix = new java.util.Vector<String>( java.util.Arrays.asList( "i" ) )
 This is how we represent the number i (square root of negative 1) in output strings.
static final java.util.Vector
< String > 
argumentPrefix = new java.util.Vector<String>( java.util.Arrays.asList( "e" ) )
 This is how we represent the number e (used for natural logarithms) in output strings.
static final java.util.Vector
< String > 
plus = new java.util.Vector<String>( java.util.Arrays.asList( "+" ) )
 This is how we represent a plus sign in output strings.

Private Member Functions

boolean roundUp ()
 The recursive rounding function.
HTMLStringRepresentation standard ()
 Produce a string representing the number without using scientific notation.
void reset ()
 Use this function whenever you change base or notation.
void setupDec ()
 This method handles setting up decimals.
void setupHex ()
 This method handles setting up hexadecimals.
void setupOct ()
 This method handles setting up octals.
void setupBin ()
 This method handles setting up binary numbers.
int maxPrecision ()
 Numbers are stored internally in IEEE-754 format.

Static Private Member Functions

static char getDigit (int d)
 We need to know how to represent integers up to 15 as char.
static int getInt (char c)
 This is effectively the reverse of getDigit().

Private Attributes

final double number
 Keep a copy of the double this object represents.
Base base
 The current Base.
Notation notation
 The current Notation.
int precision
 The current Precision.
java.util.Vector< Integer > digits
 Representation of significand digits as integers in correct base.
long exponent
 exponent

Detailed Description

Author:
J. D. Lamb
Version:
Revision:
1.13

Constructor & Destructor Documentation

jscicalc.complex.DoubleFormat.DoubleFormat ( double  number,
Base  base 
)

Member Function Documentation

static int jscicalc.complex.DoubleFormat.baseInt ( Base  base  )  [static]

This is used during rounding.

If baseInt is rounded up it must be rounded to 10 in the Base. This implies a carry operation. Others are rounded down. The returned values are 1, 7, 9 and F for Base.BINARY, Base.OCTAL, Base.DECIMAL and Base.HEXADECIMAL.

Parameters:
base A Base to work with
Returns:
The greatest digit in the base

Referenced by jscicalc.complex.DoubleFormat.roundUp().

double jscicalc.complex.DoubleFormat.getAbsNumber (  ) 

Get method for finding the absolute value of the number stored in this object.

References jscicalc.complex.DoubleFormat.number.

Referenced by jscicalc.complex.Complex.tryHTMLString().

static char jscicalc.complex.DoubleFormat.getDigit ( int  d  )  [static, private]

We need to know how to represent integers up to 15 as char.

This function does it.

Parameters:
d An integer (should be in range 0-15)
Returns:
The corresponding char

Referenced by jscicalc.complex.DoubleFormat.scientific(), and jscicalc.complex.DoubleFormat.standard().

String jscicalc.complex.DoubleFormat.getEString (  ) 

Exponents are represented as superscripts with a prefix, which may depend on the Base.

In fact, it is always a thin space, but in principle, you can change it by changing this function.

Returns:
A string to represent the exponent.
See also:
getEStringLength()

References jscicalc.complex.DoubleFormat.base.

Referenced by jscicalc.complex.DoubleFormat.scientific().

int jscicalc.complex.DoubleFormat.getEStringLength (  ) 

Exponents are represented as superscripts with a prefix, which may depend on the Base.

This function returns the nominal length of the prefix.

Returns:
A string to represent the exponent.
See also:
getEString()

References jscicalc.complex.DoubleFormat.base.

Referenced by jscicalc.complex.DoubleFormat.scientific().

static int jscicalc.complex.DoubleFormat.getInt ( char  c  )  [static, private]

This is effectively the reverse of getDigit().

We use it when extracting digits from BigDecimal.toString().

Parameters:
c A char corresponding to a digit
Returns:
The corresponding int

Referenced by jscicalc.complex.DoubleFormat.setupDec().

double jscicalc.complex.DoubleFormat.getNumber (  ) 

Get method for finding the number stored in this object.

References jscicalc.complex.DoubleFormat.number.

static void jscicalc.complex.DoubleFormat.main ( String[]  args  )  [static]
int jscicalc.complex.DoubleFormat.maxPrecision (  )  [private]

Numbers are stored internally in IEEE-754 format.

The number of digits of precision available depdends on the base and this function gives that number. The returned values are 52, 17, 14 and 13 for Base.BINARY, Base.OCTAL, Base.DECIMAL and Base.HEXADECIMAL.

Returns:
The greatest available precision

References jscicalc.complex.DoubleFormat.base.

Referenced by jscicalc.complex.DoubleFormat.DoubleFormat().

static int jscicalc.complex.DoubleFormat.midDigit ( Base  base  )  [static]

This is used during rounding.

Numbers at least as big as midDigit are rounded up. Others are rounded down. The returned values are 1, 4, 5 and 8 for Base.BINARY, Base.OCTAL, Base.DECIMAL and Base.HEXADECIMAL.

Parameters:
base A Base to work with
Returns:
The middle digit of the base

Referenced by jscicalc.complex.DoubleFormat.setPrecision().

HTMLStringRepresentation jscicalc.complex.DoubleFormat.representation (  ) 

Produce a string representing the number in current Notation and precision.

Returns:
representation of number without an exponent

Referenced by jscicalc.complex.DoubleFormat.main(), and jscicalc.complex.Complex.tryHTMLString().

void jscicalc.complex.DoubleFormat.reset (  )  [private]

Use this function whenever you change base or notation.

It also gets called when you change the precision of the output. It reconstructs the original number so that it is ready for formatting.

References jscicalc.complex.DoubleFormat.base, jscicalc.complex.DoubleFormat.digits, jscicalc.complex.DoubleFormat.exponent, jscicalc.complex.DoubleFormat.number, jscicalc.complex.DoubleFormat.setupBin(), jscicalc.complex.DoubleFormat.setupDec(), jscicalc.complex.DoubleFormat.setupHex(), and jscicalc.complex.DoubleFormat.setupOct().

Referenced by jscicalc.complex.DoubleFormat.setPrecision().

boolean jscicalc.complex.DoubleFormat.roundUp (  )  [private]

The recursive rounding function.

Do not call this directly. It gets called from setPrecision.

Returns:
false or true according as the exponent should increase or not

References jscicalc.complex.DoubleFormat.base, jscicalc.complex.DoubleFormat.baseInt(), and jscicalc.complex.DoubleFormat.digits.

Referenced by jscicalc.complex.DoubleFormat.setPrecision().

HTMLStringRepresentation jscicalc.complex.DoubleFormat.scientific (  ) 
void jscicalc.complex.DoubleFormat.setBase ( final Base  base  ) 

Set the base.

Parameters:
base The base
void jscicalc.complex.DoubleFormat.setNotation ( Notation  notation  ) 

Set the notation.

Use this every time you want a change of notation.

Parameters:
notation The notation

Referenced by jscicalc.complex.DoubleFormat.main(), and jscicalc.complex.Complex.tryHTMLString().

void jscicalc.complex.DoubleFormat.setPrecision ( int  precision  ) 

Set the precision.

The precision is the maximum number of significant digits that can be displayed. Setting the precision is equivalent to resetting the number and rounding.

Parameters:
precision The maximum number of significant digits

References jscicalc.complex.DoubleFormat.base, jscicalc.complex.DoubleFormat.digits, jscicalc.complex.DoubleFormat.exponent, jscicalc.complex.DoubleFormat.midDigit(), jscicalc.complex.DoubleFormat.reset(), and jscicalc.complex.DoubleFormat.roundUp().

Referenced by jscicalc.complex.DoubleFormat.DoubleFormat(), jscicalc.complex.DoubleFormat.main(), and jscicalc.complex.Complex.tryHTMLString().

void jscicalc.complex.DoubleFormat.setupBin (  )  [private]
void jscicalc.complex.DoubleFormat.setupDec (  )  [private]
void jscicalc.complex.DoubleFormat.setupHex (  )  [private]
void jscicalc.complex.DoubleFormat.setupOct (  )  [private]
HTMLStringRepresentation jscicalc.complex.DoubleFormat.standard (  )  [private]

Produce a string representing the number without using scientific notation.

This can produce very long strings.

Returns:
representation of number without an exponent

References jscicalc.complex.DoubleFormat.basePoint, jscicalc.complex.DoubleFormat.digits, jscicalc.complex.DoubleFormat.exponent, jscicalc.complex.DoubleFormat.getDigit(), jscicalc.complex.DoubleFormat.minus, and jscicalc.complex.DoubleFormat.number.

Referenced by jscicalc.complex.DoubleFormat.HTMLStringRepresentation.HTMLStringRepresentation().


Member Data Documentation

final java.util.Vector<String> jscicalc.complex.DoubleFormat.argumentPrefix = new java.util.Vector<String>( java.util.Arrays.asList( "e" ) ) [static]

This is how we represent the number e (used for natural logarithms) in output strings.

In principle you can change this.

final java.util.Vector<String> jscicalc.complex.DoubleFormat.basePoint = new java.util.Vector<String>( java.util.Arrays.asList( "." ) ) [static]

This is how we represent a base point in output strings.

In principle you can change this.

Referenced by jscicalc.complex.DoubleFormat.scientific(), and jscicalc.complex.DoubleFormat.standard().

final long jscicalc.complex.DoubleFormat.BIAS = 1023 [static]
java.util.Vector<Integer> jscicalc.complex.DoubleFormat.digits [private]
final long jscicalc.complex.DoubleFormat.E_MAX = 1023 [static]

Standard constant for IEEE 754 doubles.

final long jscicalc.complex.DoubleFormat.E_MIN = -1022 [static]
final String jscicalc.complex.DoubleFormat.endExponent = "</sup>" [static]

This is how we represent the end of an exponent in output strings.

Referenced by jscicalc.complex.DoubleFormat.scientific().

final String jscicalc.complex.DoubleFormat.endHTML = "</html>" [static]

This is how we represent the end of HTML in output strings.

final java.util.Vector<String> jscicalc.complex.DoubleFormat.imPrefix = new java.util.Vector<String>( java.util.Arrays.asList( "i" ) ) [static]

This is how we represent the number i (square root of negative 1) in output strings.

In principle you can change this.

final java.util.Vector<String> jscicalc.complex.DoubleFormat.infinity = new java.util.Vector<String>( java.util.Arrays.asList( "&#8734;" ) ) [static]

This is how we represent the number infinity in output strings.

In principle you can change this.

Referenced by jscicalc.complex.DoubleFormat.HTMLStringRepresentation.HTMLStringRepresentation().

final java.util.Vector<String> jscicalc.complex.DoubleFormat.minus = new java.util.Vector<String>( java.util.Arrays.asList( "&#8722;" ) ) [static]

This is how we represent a minus sign in output strings.

In principle you can change this.

Referenced by jscicalc.complex.DoubleFormat.HTMLStringRepresentation.isMinusOne(), jscicalc.complex.DoubleFormat.scientific(), and jscicalc.complex.DoubleFormat.standard().

final java.util.Vector<String> jscicalc.complex.DoubleFormat.minusInfinity = new java.util.Vector<String>( java.util.Arrays.asList( "&#8722;", "&#8734;" ) ) [static]

This is how we represent the number negative infinity in output strings.

In principle you can change this.

Referenced by jscicalc.complex.DoubleFormat.HTMLStringRepresentation.HTMLStringRepresentation().

final java.util.Vector<String> jscicalc.complex.DoubleFormat.NaN = new java.util.Vector<String>( java.util.Arrays.asList( "N", "a", "N" ) ) [static]

This is how we represent a NaN (not a number) in output strings.

In principle you can change this.

Initial value:
        new HTMLStringRepresentation( new jscicalc.StringArray(), 0 )

This is used to assign HTMLStringRepresentation objects to a null value.

It allows us to make a null assignment that can still be used.

Referenced by jscicalc.complex.Complex.tryHTMLString().

final double jscicalc.complex.DoubleFormat.number [private]
final java.util.Vector<String> jscicalc.complex.DoubleFormat.plus = new java.util.Vector<String>( java.util.Arrays.asList( "+" ) ) [static]

This is how we represent a plus sign in output strings.

In principle you can change this.

The current Precision.

final String jscicalc.complex.DoubleFormat.startExponent = "<sup style=\"font-size:60%;\">" [static]

This is how we represent the start of an exponent in output strings.

Referenced by jscicalc.complex.DoubleFormat.scientific().

final String jscicalc.complex.DoubleFormat.startHTML = "<html>" [static]

This is how we represent the start of HTML in output strings.


The documentation for this class was generated from the following file: