473,320 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

replacement for relational operations

hello to all,

Any one please tell me how to compare two variables or constants without using
relational operations.

thank you in advance,
vishnu.
Nov 13 '05 #1
2 1394
vishnu mahendra <vi*************@yahoo.com> scribbled the following:
hello to all, Any one please tell me how to compare two variables or constants without using
relational operations.


Well, if they're both numbers, substract them from each other and use
the result as an if expression. The if will be false if they're equal
or true if they're not. If you want to know which is bigger, ask a
higher C guru. I don't really know all that much about bit-twiddling
arithmetic.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"I am not very happy acting pleased whenever prominent scientists overmagnify
intellectual enlightenment."
- Anon
Nov 13 '05 #2
On 1 Dec 2003 17:37:41 GMT, in comp.lang.c , Joona I Palaste
<pa*****@cc.helsinki.fi> wrote:
vishnu mahendra <vi*************@yahoo.com> scribbled the following:
hello to all,

Any one please tell me how to compare two variables or constants without using
relational operations.


Well, if they're both numbers, substract them from each other and use
the result as an if expression. The if will be false if they're equal
or true if they're not. If you want to know which is bigger, ask a
higher C guru. I don't really know all that much about bit-twiddling
arithmetic.


how about this, for unsigned types only

if(!(a-b)) puts("the same");
else
{
while(a-- && b--) a--, b--;
if(a && !b) puts ("a was larger");
if(!a && b) puts ("b was larger");
}

you can probably trivially extend this to cover negative numbers by
operating on combinations of a and b together.

You could also to do something like this:
if(b-a)
{
errno = 0;
log(b-a);
if(errno) puts("b was smaller than a");
errno = 0;
log(a-b);
if(errno) puts("a was smaller than b");
}
else
puts ("a equals b")
although that assumes neither a=b nor b-a is outside the range of a
double, that you don't get an underflow in the log, and that
math_errhandling ORs with MATH_ERRNO. I'm sure some cleverness could
work round all this.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John Benson | last post by:
Hi, I've been looking at the "Oracle9 i Database New Features" guide, from which I quote: XML Generation In response to the challenge of generating XML in bulk from a database, XML generation...
92
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption?...
0
by: Stylus Studio | last post by:
DataDirect XQuery(TM) is the First Embeddable Component for XQuery That is Modeled after the XQuery API for Java(TM) (XQJ) BEDFORD, Mass.--Sept. 20, 2005--DataDirect Technologies...
6
by: Jonathan Ellis | last post by:
I'm working on an application that makes heavy use of Queue objects in a multithreaded environment. By "heavy" I mean "millions of calls to put and get, constituting ~20% of the app's run time."...
49
by: Mike MacSween | last post by:
I frequently hear that there isn't a commercially available dbms that fully implements the relational model. Why not? And which product comes closest. Mike MacSween
16
by: Steve S. | last post by:
I am looking for something in .NET that is functionally equivalent to the VB6 Mid() function, which allows me to replace a portion of a string at a specific position with another string. What I...
4
by: zfareed | last post by:
I would like to create a relational database using only C++. What would be more appropriate, using arrays, linked lists or some sort of templates and structs? Any advice?
13
by: sulyokpeti | last post by:
I have made a simple python module to handle SQL databases: https://fedorahosted.org/pySQLFace/wiki Its goal to separate relational database stuff (SQL) from algorythmic code (python). A SQLFace...
2
by: prakashbpl1 | last post by:
Hi All, Hi query is regarding ASP.NET and C# developement ,how to create relationship between two IList collection classes.By this collection relationship I want to create a nested GridView and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.