Public Member Functions | Public Attributes | Static Public Attributes | Package Functions | Private Member Functions | Static Private Member Functions

jscicalc.complex.Format.DoubleFormat Class Reference

A private inner class that is similar in structure to ParseBase.Number. More...

List of all members.

Public Member Functions

void round (final int sigDigits)
 Rounds to sigDigits significant digits.
int precision (int maxLength)
 The number of significant digits shown if the string representation is compressed into the given length and shown in standard notation.
int scientificPrecision (int maxLength)
 The number of significant digits shown if the string representation is compressed into the given length and shown in scientific notation.
int scientificBPrecision (int maxLength)
 The number of significant digits shown if the string representation is compressed into the given length and shown in scientific (binary) notation.
int length ()
 The length of string that would be produced in standard notation.
int scientificLength ()
 The length of string that would be produced in scientific notation.
int exponentDigits ()
 Calculate the number of digits in the exponent.
String standard ()
 Produce a string representing the number without using scientific notation.
String scientific ()
 Produce a string representing the number using scientific notation.
String scientificB ()
 Produce a string representing the binary number using scientific notation.
int scientificBLength ()
 The length of string that would be produced in scientific notation, changing a binary to 2x{decimal integer}.

Public Attributes

boolean negative
 Is number negative?
java.util.Vector< Integer > digits
 Representation of significand digits as integers in correct base.
boolean exponentNegative
 Is exponent negative?
java.util.Vector< Integer > exponentDigits
 Representation of exponent digits as integers in correct base.
int exponent
 Value of the exponent.
boolean infinity
 Is number infinite?
boolean NaN
 Is number not a number?
boolean zero
 Is number zero? Useful so we can avoid overflow in some methods.
int base
 The base as an integer.

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.

Package Functions

 DoubleFormat (double number, Base base)
 The constructor takes a double and a base.

Private Member Functions

void formatDec (double number)
 This method handles formatting decimals.
void formatHex (double number)
 This method handles formatting hexadecimals.
void formatOct (double number)
 This method handles formatting octals.
void formatBin (double number)
 This method handles formatting binary numbers.

Static Private Member Functions

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

Detailed Description

A private inner class that is similar in structure to ParseBase.Number.

It is used by Format to represent a double in a form from whch the digits can be extracted as characters.

See also:
ParseBase.Number

Constructor & Destructor Documentation

jscicalc.complex.Format.DoubleFormat.DoubleFormat ( double  number,
Base  base 
) [package]

Member Function Documentation

void jscicalc.complex.Format.DoubleFormat.formatBin ( double  number  )  [private]
void jscicalc.complex.Format.DoubleFormat.formatDec ( double  number  )  [private]
void jscicalc.complex.Format.DoubleFormat.formatHex ( double  number  )  [private]
void jscicalc.complex.Format.DoubleFormat.formatOct ( double  number  )  [private]
static char jscicalc.complex.Format.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.Format.DoubleFormat.scientific(), and jscicalc.complex.Format.DoubleFormat.standard().

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

This is effectively the reverse of getDigit().

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

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

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

int jscicalc.complex.Format.DoubleFormat.length (  ) 
int jscicalc.complex.Format.DoubleFormat.precision ( int  maxLength  ) 

The number of significant digits shown if the string representation is compressed into the given length and shown in standard notation.

The function returns zero if the string cannot be compressed that much.

Parameters:
maxLength The desired maximum length
Returns:
The number of significant digits that would result

References jscicalc.complex.Format.DoubleFormat.digits, jscicalc.complex.Format.DoubleFormat.exponent, jscicalc.complex.Format.DoubleFormat.exponentNegative, jscicalc.complex.Format.DoubleFormat.infinity, jscicalc.complex.Format.DoubleFormat.length(), jscicalc.complex.Format.DoubleFormat.NaN, jscicalc.complex.Format.DoubleFormat.negative, and jscicalc.complex.Format.DoubleFormat.zero.

Referenced by jscicalc.complex.Format.formatStandard().

void jscicalc.complex.Format.DoubleFormat.round ( final int  sigDigits  ) 

Rounds to sigDigits significant digits.

We round 0.5 (or 0.1, 0.4, 0.8) up to nearest whole and get an aswer with sigDigits digits in it.

Parameters:
sigDigits The desired number of significant digits

References jscicalc.complex.Format.DoubleFormat.base, jscicalc.complex.Format.DoubleFormat.digits, jscicalc.complex.Format.DoubleFormat.exponentDigits(), and jscicalc.complex.Format.DoubleFormat.exponentNegative.

Referenced by jscicalc.complex.Format.formatStandard().

String jscicalc.complex.Format.DoubleFormat.scientific (  ) 
String jscicalc.complex.Format.DoubleFormat.scientificB (  ) 

Produce a string representing the binary number using scientific notation.

All significant digits are used; so use round() to shorten if necessary. The exponent is rewritten as x2{decimal integer} if number is binary

Returns:
String representation of number with an exponent

References jscicalc.complex.Format.DoubleFormat.base, and jscicalc.complex.Format.DoubleFormat.scientific().

Referenced by jscicalc.complex.Format.formatStandard().

int jscicalc.complex.Format.DoubleFormat.scientificBLength (  ) 

The length of string that would be produced in scientific notation, changing a binary to 2x{decimal integer}.

Returns:
The length of the string that scientific() would produce

References jscicalc.complex.Format.DoubleFormat.base, jscicalc.complex.Format.DoubleFormat.scientific(), and jscicalc.complex.Format.DoubleFormat.scientificLength().

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

int jscicalc.complex.Format.DoubleFormat.scientificBPrecision ( int  maxLength  ) 

The number of significant digits shown if the string representation is compressed into the given length and shown in scientific (binary) notation.

The function returns zero if the string cannot be compressed that much.

Parameters:
maxLength The desired maximum length
Returns:
The number of significant digits that would result

References jscicalc.complex.Format.DoubleFormat.digits, jscicalc.complex.Format.DoubleFormat.infinity, jscicalc.complex.Format.DoubleFormat.length(), jscicalc.complex.Format.DoubleFormat.NaN, jscicalc.complex.Format.DoubleFormat.negative, jscicalc.complex.Format.DoubleFormat.scientificBLength(), jscicalc.complex.Format.z, and jscicalc.complex.Format.DoubleFormat.zero.

Referenced by jscicalc.complex.Format.formatStandard().

int jscicalc.complex.Format.DoubleFormat.scientificLength (  ) 
int jscicalc.complex.Format.DoubleFormat.scientificPrecision ( int  maxLength  ) 

The number of significant digits shown if the string representation is compressed into the given length and shown in scientific notation.

The function returns zero if the string cannot be compressed that much.

Parameters:
maxLength The desired maximum length
Returns:
The number of significant digits that would result

References jscicalc.complex.Format.DoubleFormat.digits, jscicalc.complex.Format.DoubleFormat.infinity, jscicalc.complex.Format.DoubleFormat.length(), jscicalc.complex.Format.DoubleFormat.NaN, jscicalc.complex.Format.DoubleFormat.negative, jscicalc.complex.Format.DoubleFormat.scientificLength(), jscicalc.complex.Format.z, and jscicalc.complex.Format.DoubleFormat.zero.

Referenced by jscicalc.complex.Format.formatStandard().

String jscicalc.complex.Format.DoubleFormat.standard (  ) 

Member Data Documentation

final long jscicalc.complex.Format.DoubleFormat.BIAS = 1023 [static]
final long jscicalc.complex.Format.DoubleFormat.E_MAX = 1023 [static]

Standard constant for IEEE 754 doubles.

final long jscicalc.complex.Format.DoubleFormat.E_MIN = -1022 [static]

Representation of exponent digits as integers in correct base.


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