
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( "−" ) ) |
| 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( "∞" ) ) |
| 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( "−", "∞" ) ) |
| 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 | |
| jscicalc.complex.DoubleFormat.DoubleFormat | ( | double | number, | |
| Base | base | |||
| ) |
Constructor.
| number | The number to format | |
| base | The base |
References jscicalc.complex.DoubleFormat.maxPrecision(), jscicalc.complex.DoubleFormat.notation, and jscicalc.complex.DoubleFormat.setPrecision().
Referenced by jscicalc.complex.DoubleFormat.main().
| 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.
| base | A Base to work with |
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.
| d | An integer (should be in range 0-15) |
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.
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.
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().
| c | A char corresponding to a digit |
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] |
Standard test function.
| args | Standard arguments. |
References jscicalc.complex.DoubleFormat.DoubleFormat(), jscicalc.complex.DoubleFormat.representation(), jscicalc.complex.DoubleFormat.setNotation(), jscicalc.complex.DoubleFormat.setPrecision(), and jscicalc.Notation.setScientific().
| 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.
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.
| base | A Base to work with |
Referenced by jscicalc.complex.DoubleFormat.setPrecision().
| HTMLStringRepresentation jscicalc.complex.DoubleFormat.representation | ( | ) |
Produce a string representing the number in current Notation and precision.
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.
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 | ( | ) |
Produce a string representing the number using scientific notation.
All significant digits are used; so use round() to shorten if necessary.
References jscicalc.complex.DoubleFormat.base, jscicalc.complex.DoubleFormat.basePoint, jscicalc.complex.DoubleFormat.digits, jscicalc.complex.DoubleFormat.endExponent, jscicalc.complex.DoubleFormat.exponent, jscicalc.complex.DoubleFormat.getDigit(), jscicalc.complex.DoubleFormat.getEString(), jscicalc.complex.DoubleFormat.getEStringLength(), jscicalc.complex.DoubleFormat.minus, jscicalc.complex.DoubleFormat.number, and jscicalc.complex.DoubleFormat.startExponent.
Referenced by jscicalc.complex.DoubleFormat.HTMLStringRepresentation.HTMLStringRepresentation().
| void jscicalc.complex.DoubleFormat.setBase | ( | final Base | base | ) |
Set the base.
| base | The base |
| void jscicalc.complex.DoubleFormat.setNotation | ( | Notation | notation | ) |
Set the notation.
Use this every time you want a change of notation.
| 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.
| 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] |
This method handles setting up binary numbers.
References jscicalc.complex.DoubleFormat.BIAS, jscicalc.complex.DoubleFormat.digits, jscicalc.complex.DoubleFormat.E_MIN, jscicalc.complex.DoubleFormat.exponent, and jscicalc.complex.DoubleFormat.number.
Referenced by jscicalc.complex.DoubleFormat.reset().
| void jscicalc.complex.DoubleFormat.setupDec | ( | ) | [private] |
This method handles setting up decimals.
References jscicalc.complex.DoubleFormat.digits, jscicalc.complex.DoubleFormat.exponent, jscicalc.complex.DoubleFormat.getInt(), and jscicalc.complex.DoubleFormat.number.
Referenced by jscicalc.complex.DoubleFormat.reset().
| void jscicalc.complex.DoubleFormat.setupHex | ( | ) | [private] |
This method handles setting up hexadecimals.
References jscicalc.complex.DoubleFormat.BIAS, jscicalc.complex.DoubleFormat.digits, jscicalc.complex.DoubleFormat.E_MIN, jscicalc.complex.DoubleFormat.exponent, and jscicalc.complex.DoubleFormat.number.
Referenced by jscicalc.complex.DoubleFormat.reset().
| void jscicalc.complex.DoubleFormat.setupOct | ( | ) | [private] |
This method handles setting up octals.
References jscicalc.complex.DoubleFormat.BIAS, jscicalc.complex.DoubleFormat.digits, jscicalc.complex.DoubleFormat.E_MIN, jscicalc.complex.DoubleFormat.exponent, and jscicalc.complex.DoubleFormat.number.
Referenced by jscicalc.complex.DoubleFormat.reset().
| HTMLStringRepresentation jscicalc.complex.DoubleFormat.standard | ( | ) | [private] |
Produce a string representing the number without using scientific notation.
This can produce very long strings.
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().
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.
Base jscicalc.complex.DoubleFormat.base [private] |
The current Base.
Referenced by jscicalc.complex.DoubleFormat.getEString(), jscicalc.complex.DoubleFormat.getEStringLength(), jscicalc.complex.DoubleFormat.maxPrecision(), jscicalc.complex.DoubleFormat.reset(), jscicalc.complex.DoubleFormat.roundUp(), jscicalc.complex.DoubleFormat.scientific(), and jscicalc.complex.DoubleFormat.setPrecision().
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] |
Standard constant for IEEE 754 doubles.
Referenced by jscicalc.complex.DoubleFormat.setupBin(), jscicalc.complex.DoubleFormat.setupHex(), and jscicalc.complex.DoubleFormat.setupOct().
java.util.Vector<Integer> jscicalc.complex.DoubleFormat.digits [private] |
Representation of significand digits as integers in correct base.
Referenced by jscicalc.complex.DoubleFormat.reset(), jscicalc.complex.DoubleFormat.roundUp(), jscicalc.complex.DoubleFormat.scientific(), jscicalc.complex.DoubleFormat.setPrecision(), jscicalc.complex.DoubleFormat.setupBin(), jscicalc.complex.DoubleFormat.setupDec(), jscicalc.complex.DoubleFormat.setupHex(), jscicalc.complex.DoubleFormat.setupOct(), and jscicalc.complex.DoubleFormat.standard().
final long jscicalc.complex.DoubleFormat.E_MAX = 1023 [static] |
Standard constant for IEEE 754 doubles.
final long jscicalc.complex.DoubleFormat.E_MIN = -1022 [static] |
Standard constant for IEEE 754 doubles.
Referenced by jscicalc.complex.DoubleFormat.setupBin(), jscicalc.complex.DoubleFormat.setupHex(), and jscicalc.complex.DoubleFormat.setupOct().
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.
long jscicalc.complex.DoubleFormat.exponent [private] |
exponent
Referenced by jscicalc.complex.DoubleFormat.reset(), jscicalc.complex.DoubleFormat.scientific(), jscicalc.complex.DoubleFormat.setPrecision(), jscicalc.complex.DoubleFormat.setupBin(), jscicalc.complex.DoubleFormat.setupDec(), jscicalc.complex.DoubleFormat.setupHex(), jscicalc.complex.DoubleFormat.setupOct(), and jscicalc.complex.DoubleFormat.standard().
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( "∞" ) ) [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( "−" ) ) [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( "−", "∞" ) ) [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.
The current Notation.
Referenced by jscicalc.complex.DoubleFormat.DoubleFormat(), and jscicalc.complex.DoubleFormat.HTMLStringRepresentation.HTMLStringRepresentation().
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] |
Keep a copy of the double this object represents.
Referenced by jscicalc.complex.DoubleFormat.getAbsNumber(), jscicalc.complex.DoubleFormat.getNumber(), jscicalc.complex.DoubleFormat.HTMLStringRepresentation.HTMLStringRepresentation(), jscicalc.complex.DoubleFormat.reset(), jscicalc.complex.DoubleFormat.scientific(), jscicalc.complex.DoubleFormat.setupBin(), jscicalc.complex.DoubleFormat.setupDec(), jscicalc.complex.DoubleFormat.setupHex(), jscicalc.complex.DoubleFormat.setupOct(), and jscicalc.complex.DoubleFormat.standard().
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.
int jscicalc.complex.DoubleFormat.precision [private] |
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.
1.7.1