Re: How to find the greatest of two numbers without using thecomparison operators?
- From: "William M. Klein" <wmklein@xxxxxxxxxxxxxxxxx>
- Date: Fri, 31 Aug 2007 18:31:22 GMT
If you didn't need to use the IF statement, I can think of a number of
(ridiculously expensive) ways to do it. (I was thinking of these when I wasn't
looking at the original assignment where we knew the items were numeric)
- Create a temp file and SORT it
- Create an indexed file (and see what entry you get first)
- Put them into a table and use SEARCH (I am not even certain this could work)
And then there is my favorite (that actually meets the original assignment)
- use Object Orientation and create a method for comparing two items, e.g.
If whatever::"compare" (Field-A Field-B) Numeric
Then Display "Field-A > Field-B)
.... where the compare method returns zero if the first operand is > than the
second
it returns spaces if the 2nd operand is > than the first
- it returns high-values if they are equal (so you would need to do a 2nd test)
***
Don't you think THAT would impress the teacher <G>
--
Bill Klein
wmklein <at> ix.netcom.com
"Rick Smith" <ricksmith@xxxxxxx> wrote in message
news:13dggs41m0sc4c@xxxxxxxxxxxxxxxxxxxxx
"Frank Swarbrick" <Frank.Swarbrick@xxxxxxxxxxxxxx> wrote in message
news:46D7E17F.6F0F.0085.0@xxxxxxxxxxxxxxxxx
[snip]
Not sure why you need this, but perhaps FUNCTION MAX could give you whatyou
want?
COMPUTE MAX = FUNCTION MAX(A B)
Another intereting approach might be:
-----
evaluate
function ord-max(A B) - function ord-min(A B)
when 1
display "A is less than B"
when 0
display "A is equal to B"
when -1
display "A is greater than B"
end-evaluate
-----
A and B may be either numeric or alphanumeric, as long as
they are the same.
.
- References:
- How to find the greatest of two numbers without using the comparison operators?
- From: Aparajita
- Re: How to find the greatest of two numbers without using the comparison operators?
- From: Frank Swarbrick
- Re: How to find the greatest of two numbers without using thecomparison operators?
- From: Rick Smith
- How to find the greatest of two numbers without using the comparison operators?
- Prev by Date: Re: How to find the greatest of two numbers without using the comparison operators?
- Next by Date: Re: How to find the greatest of two numbers without using the comparison operators?
- Previous by thread: Re: How to find the greatest of two numbers without using thecomparison operators?
- Next by thread: Re: How to find the greatest of two numbers without using the comparison operators?
- Index(es):
Relevant Pages
|