Class Number
The NUMBER() object is used for High Precision Math calculations.
Syntax
[<oRef> =] new Number([<nNumber expN>])
<oRef>
A variable or property in which to store a reference to the newly created Number object.
<nNumber expN>
An optional number or numeric expression
Description
It allows for various properties and events to be used to help with very large numbers. This implements most of the specification for the IEEE 754 standard (http://speleotrove.com/decimal/)
The Number class contains a value property that can a single value at a time in high precision format. It has other properties for adjusting rounding, precision, maximum exponents, .
It has numerous mathematical methods for performing common operations on the value as well as some methods which use the value as input and return a result based on the value.
Setting the value:
You can set the value of a number object either at construction or anytime later as follows:
At construction:
n = new number(<somevalue> )
After construction:
n.assign(<somevalue> )
or
n.value = <somevalue>
Example:
SET PRECISION TO 34
SET DECIMAL TO 34
MYNUM1 = NEW NUMBER(24234321512514.2314134)
MYNUM2 = NEW NUMBER(234234234.7897070)
MYTOT = NEW NUMBER(MYNUM1 / MYNUM2)
? “Total is -> “ + MYTOT.VALUE
Another key feature of the NUMBER object is that is has its own precision built into the implementation, which means the SET PRECISION setting does not apply to it. This is because he has own setting of precision and it is number of significand digits can be stored; a value in the range 1 through 999 999 999.
Database Storage:
Do to current limitations in both dBASE and also the BDE, a Number() object cannot be stored in a field in the database. There is no corresponding data type to represent that natively. In this case, if you are using dBASE or Paradox files, the value must be stored as a String data type.
Key in mind that some databases could support high precision math storage, please refer to the particular database documentation for further insights and details.
PROPERTIES
Property |
Default |
Description |
baseClassName |
NUMBER |
The default baseClassName of the component |
className |
NUMBER |
The user defined or default className of the component |
clamp |
False |
The clamp field controls explicit exponent clamping, as is applied when a result is encoded in one of the compressed formats.
When False, a result exponent is limited to a maximum of emax and a minimum of emin (for example, the exponent of a zero result will be clamped to be in this range).
When True, a result exponent has the same minimum but is limited to a maximum of emax–(digits–1). As well as clamping zeros, this may cause the coefficient of a result to be padded with zeros on the right in order to bring the exponent within range.
For example, if emax is +96 and digits is 7, the result 1.23E+96 would have a [sign, coefficient, exponent] of [0, 123, 94] if clamp were False, but would give [0, 1230000, 90] if clamp were True.
In addition, when True, clamp limits the length of NaN payloads to digits–1 (rather than digits) when constructing a NaN by conversion from a string. |
digits |
1 |
The digits field is used to set the precision to be used for an operation. The result of an operation will be rounded to this length if necessary. The valid range must have a value in the range 1 through 999,999,999. This cannot be set any higher than the Precision number. |
emax |
999999999 |
The emax field is used to set the magnitude of the largest adjusted exponent that is permitted. The adjusted exponent is calculated as though the number were expressed in scientific notation (that is, except for 0, expressed with one non-zero digit before the decimal point). If the adjusted exponent for a result or conversion would be larger than emax then an overflow results. The valid range must have a value in the range 0 through 999,999,999. |
emin |
-999999999 |
The emin field is used to set the smallest adjusted exponent that is permitted for normal numbers. The adjusted exponent is calculated as though the number were expressed in scientific notation (that is, except for 0, expressed with one non-zero digit before the decimal point).
If the adjusted exponent for a result or conversion would be smaller than emin then the result is subnormal. If the result is also inexact, an underflow results. The exponent of the smallest possible number (closest to zero) will be emin–digits+1. emin is usually set to –emax or to –(emax–1).
emin is of type int32_t, and must have a value in the range –999,999,999 through 0. |
exponent |
0 |
The exponent field holds the exponent of the number. Its range is limited by the requirement that the range of the adjusted exponent of the number be balanced and fit within a whole number of decimal digits (in this implementation, be –999,999,999 through +999,999,999). The adjusted exponent is the exponent that would result if the number were expressed with a single digit before the decimal point, and is therefore given by exponent+digits-1.
When the extended flag in the context is 1, gradual underflow (using subnormal values) is enabled. In this case, the lower limit for the adjusted exponent becomes –999,999,999–(precision–1), where precision is the digits setting from the context; the adjusted exponent may then have 10 digits. |
level |
1 - ANSI |
This refers to either IEEE or ANSI calculation method. |
mantissa |
0 |
The use of mantissa to refer to significant digits in a floating point number or scientific notation. Example: 3.14159 the mantissa would represent 0.14159 |
precision |
34 |
Determines the number of digits used when comparing numbers. |
roundType |
0 – Half Even |
The round field is used to select the rounding algorithm to be used if rounding is necessary during an operation. It must be one of the values in the rounding enumeration: · 0
– Half Even; round to nearest; if equidistant, round so that the
final digit is even. · 2
– Half Down; round to nearest; if equidistant, round down. |
signed |
false |
Having both positive and negative varieties. To be signed would add the ‘-‘ to the number. |
state |
0 - Zero |
represents the state of a number |
status |
0 - None |
The status field comprises one bit for each of the exceptional conditions described in the specifications. Once set, a bit remains set until cleared by the user, so more than one condition can be recorded.
status is of type unsigned integer. Bits in the field must only be set if they are defined. In use, bits are set by the Number library modules when exceptional conditions occur, but are never reset. The library user should clear the bits when appropriate (for example, after handling the exceptional condition), but should never set them. |
value |
0 |
This is the value established once a number has been assigned to the NUMBER() object. |
EVENTS
No Events
METHODS
This following is how a method would be called:
mytotal = new number()
mytot1al.value := 103461.9108273030499875735085908207
? mytotal.toString()
? mytotal.tonumber()
? mytotal.sqrt()
NOTE: Calling methods do not change the value property. They return a result based on the value property.
Method Name |
Parameters |
Functionality |
abs |
None |
Returns the absolute value of a specified number. |
acos |
None |
Returns the inverse cosine (arccosine) of a number (in radians) |
add |
<Number> |
Addition.
Example: newnum = new number() newnum.value = 10 //value would be 10 ? newnum.add(10) //add 10 to the value ? newnum.value
Output: 20 10
Remember the methods do not change the value of the number object; it does use it for the calculation. |
asin |
None |
Returns the inverse sine (arcsine) of a number (in radians) |
atan |
None |
Returns the inverse tangent (arctangent) of a number (in radians) |
assign |
<nExp> |
Assigns a new numeric value |
cos |
None |
Returns the trigonometric cosine of an angle (in radians) |
degree |
|
Returns the degrees from the angles measured in radians.
Example: set precision to 34 set decimal to 34 num1 = new number(.5) ? num1.degree()
Output: 28.64788975654116043839907740705258 |
div |
<Number> |
Division by <Number>
Example: newnum = new number() newnum.value = 10 //value would be 10 ? newnum.div(2) //divides newnum by 2 ? newnum.value
Output: 5 10
Remember the methods do not change the value of the number object; it does use it for the calculation. |
exp |
None |
Returns e raised to a specified power. |
isFinite |
None |
This function is used to test whether a number is finite. Returns 1 (true) if the number is finite, or 0 (false) otherwise (that is, it is an infinity or a NaN). |
isFloat |
None |
This function is used to test whether a number is a Float. Returns 1 (true) if number is a Float or 0 (false) otherwise. |
isInf |
None |
This function is used to test whether a number is infinite. Returns 1 (true) if the number is infinite, or 0 (false) otherwise (that is, it is a finite number or a NaN). |
isInt |
None |
This function is used to test whether a number is an Integer. Returns 1 (true) if number is an Integer or 0 (false) otherwise. |
isNaN |
None |
This function is used to test whether a number is a NaN (Not a Number). Returns 1 (true) if the number is a NaN, or 0 (false) otherwise. |
isNeg |
None |
This function is used to test whether a number is negative (either minus zero, less than zero, or a NaN with a sign of 1). Returns 1 (true) if the number is negative or 0 (false) otherwise. |
isZero |
None |
This function is used to test whether a number is a zero (either positive or negative). Returns 1 (true) if the number is zero, or 0 (false) otherwise. |
log |
None |
Returns the logarithm to the base e (natural logarithm) of a specified number. |
log10 |
None |
Returns the logarithm to the base 10 of a specified number. |
logB |
None |
Returns a floating-point value extracted exponent from the internal floating-point representation of x. |
mod |
None |
Returns the modulus (remainder) of one number divided by another. |
mul |
<nMultiplier> |
Multiplication
Example: newnum = new number() newnum.value = 10 //value would be 10 ? newnum.mul(10) //Multiply by 10 ? newnum.value
Output: 100 10
Remember the methods do not change the value of the number object; it does use it for the calculation. |
negate |
|
|
pi |
None |
Returns the approximate value of pi, the ratio of a circle’s circumference to its diameter. |
pow |
|
Exponentiation is a mathematical operation, written as bn, involving two numbers, the base b and the exponent (or index or power) n. |
radian |
None |
Returns the Radians calculated form the NUMBER.VALUE
Example: set precision to 34 set decimal to 34 num1 = new number(34) ? num1.radian()
Output: 0.5934119456780720561540548612861283 |
round |
<nRoundDecimalPlace> |
Sets the number
object to a new number rounded to the nearest integer or a specified
number of decimal places. n.round(1) ?n // returns 1.6 |
sin |
None |
Returns the trigonometric sine of an angle (in radians) |
sqrt |
None |
Returns the square root of a number. |
sub |
<nSubtractNumber> |
Subtraction
Example: newnum = new number() newnum.value = 10 //value would be 10 ? newnum.sub(10) //Subtract 10 from the value ? newnum.value
Output: 0 10
Remember the methods do not change the value of the number object; it does use it for the calculation. |
tan |
None |
Returns the trigonometric tangent of an angle (in radians) |
toNumber |
None |
Returns the number from the object. |
toSting |
None |
Returns the string representation of the value properties of the object. |