Re: Subtract smaller or larger number from x?
- From: "Barry" <barryg@xxxxxxxxxxxxxxxxxx>
- Date: Wed, 29 Mar 2006 06:22:24 -0600
<eksamor@xxxxxxxxx> wrote in message
news:1143629909.584403.132980@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have a number x. I would now like to find the difference between this
number x and another number y.
But y can be either larger or smaller than x. Currently I check if the
number y is greater or smaller than x:
int diff; // the difference between x and y
if (y > x){
diff = y-x;
}else{
diff = x-y;
}
is there not a more elegant way to do this when I would like the
difference to be a positive value??
Since this looks like C, abs(), labs() or labs() may be useful
.
- References:
- Subtract smaller or larger number from x?
- From: eksamor
- Subtract smaller or larger number from x?
- Prev by Date: Re: Subtract smaller or larger number from x?
- Next by Date: Re: Yacc = Bison???
- Previous by thread: Re: Subtract smaller or larger number from x?
- Next by thread: Re: Subtract smaller or larger number from x?
- Index(es):
Relevant Pages
|