This site's content was compiled from 1993 to 2006. Beyond that, Google is your friend.
Peter Horan
When entering numerical data in a text window, it is best to inform the user that it is invalid as soon as an unwanted character is entered. Class FLOAT_FILTER addresses this problem for real numbers.
However, incomplete numerical strings can fail the tests "is_real" or "is_integer". For example, the strings "", "+" and "." fail. But these are legitimate prefixes of numerical strings.
In a similar manner, the expected input may be limited in range. For example, x >= x_min, x =< x_max. Checking these limits during data entry causes problems especially if the value x = 0 is not in range. For example, in setting an error percentage limit, x >= 0.01% and x <= 100% During entry, the set of prefixes representing x is {"0", "0.", "0.0"} all of which fall outside the permitted range. Hence, the need for routines which allow for these cases.
The class FLOAT_FILTER has the following features:
is_float_prefix(s: STRING): BOOLEAN
require
s /= Void
ensure
-- Result = "s" is a valid numerical prefix
end
definitely_smaller(s, lower_limit: STRING): BOOLEAN
require
lower_limit.is_real
is_float_prefix(s)
ensure
-- Result = "s" is the prefix of
-- a numerical string < lower_limit
end
definitely_bigger(s, upper_limit: STRING): BOOLEAN
require
upper_limit.is_real
is_float_prefix(s)
ensure
-- Result = "s" is the prefix of
-- a numerical string > lower_limit
end
The routines "definitely_smaller" and "definitely_bigger" perform simple comparisons in the cases where "lower_limit" is negative or "upper_limit" is positive, respectively, or when the quantities contain no decimal point. However, when the numerical string contains a decimal point, the comparison must be done by comparing the input string with the limit string truncated to the same number of fractional digits. For example, s = 0.2 is not definitely smaller than lower_limit = 0.25 because it could be extended to s = 0.25 and be in range. That is, the call definitely_smaller("0.2", "0.25") should return False. However, definitely_smaller("0.1", "0.25") should return True.