Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: How to find the greatest of two numbers without using thecomparison operators?
"Frank Swarbrick" <Frank.Swarbrick@efirstbank.com> wrote in message
news:46D7E17F.6F0F.0085.0@efirstbank.com...
[snip]
> Not sure why you need this, but perhaps FUNCTION MAX could give you what
you
> 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.




Report this thread to moderator Post Follow-up to this message
Old Post
Rick Smith
08-31-07 11:58 PM


Re: How to find the greatest of two numbers without using thecomparison operators?
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 wor
k)

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 th
e
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 te
st)

***

Don't you think THAT would impress the teacher <G>

--
Bill Klein
wmklein <at> ix.netcom.com
"Rick Smith" <ricksmith@mfi.net> wrote in message
news:13dggs41m0sc4c@corp.supernews.com...
>
> "Frank Swarbrick" <Frank.Swarbrick@efirstbank.com> wrote in message
> news:46D7E17F.6F0F.0085.0@efirstbank.com...
> [snip] 
> you 
>
> 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.
>
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
William M. Klein
08-31-07 11:58 PM


Re: How to find the greatest of two numbers without using thecomparison operators?

"Rick Smith" <ricksmith@mfi.net> wrote in message
news:13dggs41m0sc4c@corp.supernews.com...
>
> "Frank Swarbrick" <Frank.Swarbrick@efirstbank.com> wrote in message
> news:46D7E17F.6F0F.0085.0@efirstbank.com...
> [snip] 
> you 
>
> 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.
>
A nice solution Rick. Good job.

(At least you thought about it ... :-))

Pete
--
"I used to write COBOL...now I can do anything."



Report this thread to moderator Post Follow-up to this message
Old Post
Pete Dashwood
08-31-07 11:58 PM


Re: How to find the greatest of two numbers without using thecomparison operators?

"William M. Klein" <wmklein@nospam.netcom.com> wrote in message
news:_7ZBi.297833$rk4.155800@fe09.news.easynews.com...
> 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)
>
Bill, it doesn't matter if the operands are numeric or not. It is the
principle of doing "arithemetic" (in the sense that the ALU does
"arithmetic") on them, and testing the resulting sign that matters.
(Although I really liked Rick's Evaluate approach as well...) It is not for
nothing that the the heart of the CPU is an "Arithmetic Logic Unit"... :-)

> - 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)

C# has almost exactly such a method... as a kind of "blanket" for cases
where strings need comparison and the usual innate methods are unsuitable
:-) (Fortunately, you only need to use it rarely...:-))
>
>
> ... 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>
>

I think that, in the unlikely event the teacher reads this thread, he/she
will run screaming from the room... :-)

Pete
--
"I used to write COBOL...now I can do anything."



Report this thread to moderator Post Follow-up to this message
Old Post
Pete Dashwood
09-01-07 02:57 AM


Re: How to find the greatest of two numbers without using thecomparison operators?
"Pete Dashwood" <dashwood@removethis.enternet.co.nz> wrote in message
news:5jro26F117mpU1@mid.individual.net...
>
>
> "Rick Smith" <ricksmith@mfi.net> wrote in message
> news:13dggs41m0sc4c@corp.supernews.com...
[snip] 
> A nice solution Rick. Good job.
>
> (At least you thought about it ... :-))

I was just using some erudition triggered by the mention
of intrinsic functions. <g>




Report this thread to moderator Post Follow-up to this message
Old Post
Rick Smith
09-01-07 02:57 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Cobol archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:42 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.