|
Comparing Numeric Expressions
GPP compares numeric expressions in a non-standard way. Instead of simply comparing the numeric values (double precision floating point), it takes into account the formatting of values as they are sent to output.
If an operand of the comparison is a variable, it is temporarily printed using the variable format, and the resulting string is converted back into a number before it is used in the comparison.
For instance, suppose two variables, X and Y, both have a value of 11/3 (3.666666…). However, they have different formats. When formatted, X uses 3 fractional digits, so it is formatted as 3.667, while Y uses 1 fractional digit and is formatted as 3.7. When compared by GPP, these two numbers will come out as non-equal (although internally, they have the same value)! It is therefore not recommended to compare variables of different formats, as results are difficult to predict.
GPP will ignore minor formatting issues, such as leading or trailing zeros. For instance, suppose now X and Y both have the value of 2.5. But Y is formatted with at least 3 fractional digits, with trailing zeros. Once formatted, X will result in 2.5, while Y will give 2.500. In such a case, GPP will treat them as equal. GPP2 also ignores other minor formatting options, such as the characters used for the plus or minus sign or whether a decimal point is used for integer values. So, GPP2 will treat "2", "+2", "2." and "2.000" as equal.
When a non-variable expression is compared to a variable, the non-variable expression is also formatted using the variable format, to ensure proper comparison.
When none of the two operands is a simple variable (For example, X + 3 <= Y ** 2), both expressions are formatted using the REAL format, before being compared.
|