Aspen SCM‎ > ‎Expert System‎ > ‎1. Elements‎ > ‎

1.5 How Aspen SCM Expert System Compares Numbers

Types of Number

Aspen SCM Expert System can hold numbers as floating point, integers or character strings. Character strings can also hold character data, i.e. strings which cannot be construed as numbers. We shall use the following terms to refer to values:

  • numeric, for values which are held as floating point or integer;

  • quasi-numeric, for character values which are routinely interpreted as numbers; these include strings comprising a maximum of 7 digits plus optionally a decimal point and a minus sign, e.g. 1, 0.00003, 56371.3;

  • scientific, for character values which use exponential notation, e.g. 1e5, 0.00034E+42;

  • extended precision, for character strings with more than 7 digits which may be interpreted as numbers;

  • character, for character strings which cannot be interpreted as numbers.

Types of Comparison

Aspen SCM Expert System appears to have four different methods of comparing values:

  • floating point comparison, in which the values are compared as floating point and declared to be equal if the difference between them is less than 0.000001;

  • integer comparison, in which the values are compared as integers;

  • extended precision comparison, in which the values are compared as character strings but using numeric conventions so that -123456789 < -123456000 and 123456789 > 12349000;

  • character comparison, in which the character strings are compared using the ASCII collating sequence, under this -0.00012345 > -0.0001 and 0.1000000 ?? 0.1. Blanks and leading zeroes are significant under character comparison and must match identically for two strings to be equal.

We shall refer to the first two of these as numeric comparison.

Type of Comparison Used

When Aspen SCM Expert System compares values it works as follows:


Numeric

Quasi-numeric

Scientific

Extended Precision

Character

Numeric

Numeric

Numeric

Numeric

Numeric

Character

Quasi-numeric

Numeric

Numeric

Character

Character

Character

Scientific

Numeric

Character



Character

Extended Precision

Numeric

Character


Extended Precision

Character

Character

Character

Character

Character

Character

Character

Note that scientific notation and extended precision are supported in a limited way. A value such as 1E8 is regarded as a character string until such time as it is forced to be numeric by being used where it is forced to be a number. Thus if a numeric value is compared against it, it is interpreted as a number whereas if a quasi-numeric character string is compared against it, it is regarded as a character string. Hence 2 GT 1E8 is TRUE.

Comparison Against Zero and Effect of Leading Blanks

Another surprise occurs on comparisons of quasi-numeric strings against quasi-numeric zero. This should be a numeric test (and is a numeric test if the test is against any quasi-numeric value other than zero). But in the case of zero, a character test is performed (presumably because there is no need to do a subtraction before testing the numeric value). This means that leading blanks are significant and must match identically.

A classic error occurs when a character string has been read from a data file and is then compared against a quasi-numeric zero. Thus:

AND ?NUM = SUBSTR(?STRING,51,8)
AND ?NUM EQ 0 OR …

reads the value between characters 51 and 58 of ?STRING into ?NUM. If ?STRING contains a zero in position 58 the value of ?NUM is 7 blanks followed by a zero. The character comparison against a single zero resolves FALSE.

If the comparison is against a numeric zero or a quasi-numeric value other than zero, the interpreter converts the string variable to a number and then performs a numeric comparison. The code therefore works as expected.

When a character comparison is made which involves a numeric value it is the external representation of the value which is used. This is the way in which the value appears in ETRACE.


Back                                Next

Comments