|
-
Dec 28th, 2006, 05:25 AM
#1
Thread Starter
New Member
comparison which is greater
hi all ,
i want to perform comparison between two variable and find out which is greater without using comparison operator.
give me suitable answer,
regards,
abhishek mishra
-
Dec 28th, 2006, 05:42 AM
#2
Re: comparison which is greater
You can perform the substraction and compare the result with 0 (zero):
VB Code:
Dim A As Double, B As Double
A = 0.1
B = 0.2
Select Case (A - B)
Case 0
Debug.Print "A equals B"
Case Is < 0
Debug.Print "B is grater then A"
Case Else
Debug.Print "A is grater then B"
End Select
-
Dec 28th, 2006, 05:46 AM
#3
Re: which is greater
Althoug I think it's utter nonsense to do so:
Sub test3()
A = 50
B = 20
C = A - B
If (C = Abs(C)) Then MsgBox "A = larger"
End Sub
 why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
for every question you ask provide an answer on another thread.
-
Dec 28th, 2006, 05:50 AM
#4
Re: comparison which is greater
 Originally Posted by abhi.ashok
i want to perform comparison between two variable and find out which is greater without using comparison operator.
But why do you want to do so
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Dec 28th, 2006, 05:58 AM
#5
Re: comparison which is greater
 Originally Posted by ganeshmoorthy
But why do you want to do so
Isn't it obvious? 
@abhi.ashok: i don't believe it's possible, but if it is, it may not be so easy as you may think.
-
Dec 28th, 2006, 06:06 AM
#6
Re: comparison which is greater
What is your purpose of doing so? Why make your life difficult?
-
Dec 28th, 2006, 06:12 AM
#7
Re: comparison which is greater
 why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
for every question you ask provide an answer on another thread.
-
Dec 28th, 2006, 12:05 PM
#8
Re: which is greater
Duplicate threads merged.
Please do not double post the same question.
-
Dec 28th, 2006, 12:54 PM
#9
Re: which is greater
Alternatively to the above, test:
If A > B, then mod(A/B) > 1 and so you attempt to sqrt a negative number, which will throw an error.
If B > A, then mod(A/B) < 1 and the sqrt succeeds.
Not as good a method as Dnereb's, because you specifically design an error into it, but an alternative nevertheless.
-
Dec 29th, 2006, 01:16 PM
#10
Hyperactive Member
Re: comparison which is greater
 Originally Posted by abhi.ashok
hi all ,
i want to perform comparison between two variable and find out which is greater without using comparison operator.
give me suitable answer,
regards,
abhishek mishra
give me a suitable answer. I seemed to remember this as a homework quesiton from college which I am sure this is.
On a very low very you can do bitwise operation to compare the bits of the variable. Pretend you are designing a circuit for a comparison operator on a cpu.
ok, i am going to assume you know binary, how to add and subtract in binary, 2 compliment, and you know boolean math. If you don't know these you arent going to understand this nor will understand how a processor works.
anyway, just do binary subtraction for each bit of the 2 numbers using AND and Invert. if the resultant MSB is 1 then number is negative and first number was smaller, expect in the case of two negative numbers.
Last edited by superbovine; Dec 29th, 2006 at 02:07 PM.
-
Dec 30th, 2006, 09:01 AM
#11
Hyperactive Member
Re: which is greater
It could also be done with boolean operators.. Are you allowed to compare the numbers 1 bit at a time? Or are you forced to compare the entire value on a single line?
Boolean math can actually eliminate/transform virtually any IF statement..
Doh, how did I overlook the fact that what I am saying was just said by SuperBovine..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|