|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Dear all,
In C, x % y = ( x -(x/y) * y); is n't it ...???? where x and y are integers and y not equal to zero is there any other identity involving % operator..??? or any other binary operator..?? for example w % n = w & (n-1); when n is a power of 2. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
sophia wrote:
> Dear all, > > In C, x % y = ( x -(x/y) * y); is n't it ...???? where x and y are > integers and y not equal to zero No. Try x = 5 and y = 3. Straightaway x/y will give you 0. <snip> |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
santosh wrote:
> sophia wrote: > >> Dear all, >> >> In C, x % y = ( x -(x/y) * y); is n't it ...???? where x and y are >> integers and y not equal to zero > > No. > > Try x = 5 and y = 3. Straightaway x/y will give you 0. > > <snip> Sorry to the OP. This is wrong. Your equation is indeed correct. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Apr 25, 2:06pm, santosh <santosh....@gmail.com> wrote:
> sophia wrote: > > Dear all, > > > In C, x % y = ( x -(x/y) * y); is n't it ...???? where x and y are > > integers and y not equal to zero > > No. > > Try x = 5 and y = 3. Straightaway x/y will give you 0. see this #include<stdio.h> #include<stdlib.h> int main(void) { int x,y; x=5,y=3; printf("\n%d", ( x -(x/y) * y)); printf("\n%d", x%y); return EXIT_SUCCESS; } |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
sophia wrote:
> On Apr 25, 2:06pm, santosh <santosh....@gmail.com> wrote: >> sophia wrote: >> > Dear all, >> >> > In C, x % y = ( x -(x/y) * y); is n't it ...???? where x and y are >> > integers and y not equal to zero >> >> No. >> >> Try x = 5 and y = 3. Straightaway x/y will give you 0. > > see this > #include<stdio.h> > #include<stdlib.h> > > int main(void) > { > int x,y; > x=5,y=3; > > printf("\n%d", ( x -(x/y) * y)); > printf("\n%d", x%y); > > return EXIT_SUCCESS; > } Yes, my response was incorrect. I'll leave it to the others to answer your original query since it's meaning is rather unclear to me. |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
There are one more interesting fact for integers:
x%y==0 <==> (x/y)*y==x sophia wrote: > Dear all, > > In C, x % y = ( x -(x/y) * y); is n't it ...???? where x and y are > integers and y not equal to zero > > is there any other identity involving % operator..??? or any other > binary operator..?? > > for example > > w % n = w & (n-1); when n is a power of 2. > |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
santosh wrote:
> sophia wrote: > >> In C, x % y = ( x -(x/y) * y); is n't it ...???? where x and y >> are integers and y not equal to zero > > No. Try x = 5 and y = 3. Straightaway x/y will give you 0. Huh? I find x/y yields 1. -- [mail]: Chuck F (cbfalconer at maineline dot net) [page]: <http://cbfalconer.home.att.net> Try the download section. ** Posted from http://www.teranews.com ** |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
On Fri, 25 Apr 2008 01:30:05 -0700 (PDT), sophia
<sophia.agnes@gmail.com> wrote: >Dear all, > >In C, x % y = ( x -(x/y) * y); is n't it ...???? where x and y are >integers and y not equal to zero > >is there any other identity involving % operator..??? or any other >binary operator..?? > >for example > > w % n = w & (n-1); when n is a power of 2. If your instructor is spending this much time on esoteric equivalences, you need to find a new one. If you are doing this yourself, your time would be much better spent on mastering the fundamental concepts of the language before you go looking for "cute tricks". Remove del for email |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
On Fri, 25 Apr 2008 12:27:18 +0300,
Eugeny Myunster <box@eugeny.ws> wrote: > sophia wrote: >> Dear all, >> >> In C, x % y = ( x -(x/y) * y); is n't it ...???? where x and y are >> integers and y not equal to zero > There are one more interesting fact for integers: > > x%y==0 <==> (x/y)*y==x To me, that seems to be the same 'fact'. Martien -- | Martien Verbruggen | We are born naked, wet and hungry. Then | things get worse. | |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
sophia wrote:
> Dear all, > > In C, x % y = ( x -(x/y) * y); is n't it ...???? where x and y are > integers and y not equal to zero > > is there any other identity involving % operator..??? or any other > binary operator..?? > > for example > > w % n = w & (n-1); when n is a power of 2. int n_is_Power_of_two(long unsigned n) { return (n & n - 1) == 0 && n != 0; } int n_is_Power_of_four(long unsigned n) { return (n & n - 1) == 0 && n % 3 == 1; } int n_is_Power_of_eight(long unsigned n) { return (n & n - 1) == 0 && n % 7 == 1; } -- pete |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
"sophia" <sophia.agnes@gmail.com> wrote in message
news:79d97bf1-4071-4637-934e-21428324a1b0@y22g2000prd.googlegroups.com... > Dear all, > > In C, x % y = ( x -(x/y) * y); is n't it ...???? where x and y are > integers and y not equal to zero WTF? x%y does not always equal zero. What use woudl that be?! |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
sophia <sophia.agnes@gmail.com> writes:
> In C, x % y = ( x -(x/y) * y); is n't it ...???? where x and y are > integers and y not equal to zero Yes, but you have to add also that x/y is representable. When x = INT_MIN and y = -1, x/y may not be representable. > is there any other identity involving % operator..??? or any other > binary operator..?? > > for example > > w % n = w & (n-1); when n is a power of 2. Again you have to add extra conditions. It requires n > 1 and w >= 0. -- Ben. |
|
|
|
#13 |
|
Messages: n/a
Hébergeur: |
"ArWeGod" <ArWeGod?@sbcglobal.net> writes:
> "sophia" <sophia.agnes@gmail.com> wrote in message > news:79d97bf1-4071-4637-934e-21428324a1b0@y22g2000prd.googlegroups.com... >> Dear all, >> >> In C, x % y = ( x -(x/y) * y); is n't it ...???? where x and y are >> integers and y not equal to zero > > WTF? x%y does not always equal zero. What use woudl that be?! The expression given is a C arithmetic expression. It is not intended to be read as mathematics. -- Ben. |
|
|
|
#14 |
|
Messages: n/a
Hébergeur: |
On 27 Jul, 15:29, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:
> "ArWeGod" <ArWeG...@sbcglobal.net> writes: > > "sophia" <sophia.ag...@gmail.com> wrote in message > >news:79d97bf1-4071-4637-934e-21428324a1b0@y22g2000prd.googlegroups.com.... > >> In C, x % y = ( x -(x/y) * y); is n't it ...???? where x and y are > >> integers and y not equal to zero > > > WTF? x%y does not always equal zero. What use woudl that be?! > > The expression given is a C arithmetic expression. It is not intended > to be read as mathematics. I'd have said exactly the opposite. It is not a C expression (because x%y does not make sense on the right hand side of an assignment), but it *is* a valid mathematical expression (given a suitable definition of /). I've occaisionally found it useful in languages that don't provide a remainder operator. -- Nick Keighley A lot of the c.l.c. verbiage seems to be devoted to the numerical density of cavorting nubile seraphim upon pinheads. CBFalconer |
|
|
|
#15 |
|
Messages: n/a
Hébergeur: |
Nick Keighley wrote:
> .... snip ... > > -- > Nick Keighley > > A lot of the c.l.c. verbiage seems to be devoted to the numerical > density of cavorting nubile seraphim upon pinheads. > CBFalconer Did I ever say that? I don't remember it. Seems accurate, though. -- [mail]: Chuck F (cbfalconer at maineline dot net) [page]: <http://cbfalconer.home.att.net> Try the download section. |
|
|
|
#16 |
|
Messages: n/a
Hébergeur: |
On 28 Jul, 20:25, CBFalconer <cbfalco...@yahoo.com> wrote:
> Nick Keighleywrote: > > -- > >Nick Keighley > > > A lot of the c.l.c. verbiage seems to be devoted to the numerical > > density of cavorting nubile seraphim upon pinheads. > > CBFalconer > > Did I ever say that? I don't remember it. Seems accurate, though. It was from some time ago, but I *believe* I correctly attributed it. <google> yep, 2001-03-02 subject: "Sleep command for noninteger time" -- Nick Keighley "Resistance is futile. Read the C-faq." -- James Hu (c.l.c.) |
|
|
|
#17 |
|
Messages: n/a
Hébergeur: |
Nick Keighley wrote:
> CBFalconer <cbfalco...@yahoo.com> wrote: >> Nick Keighleywrote: > >>> -- >>> Nick Keighley >> >>> A lot of the c.l.c. verbiage seems to be devoted to the numerical >>> density of cavorting nubile seraphim upon pinheads. >>> CBFalconer >> >> Did I ever say that? I don't remember it. Seems accurate, though. > > It was from some time ago, but I *believe* I correctly attributed it. > > <google> > > yep, 2001-03-02 > subject: "Sleep command for noninteger time" Oh my. Only 7 years ago, and what a difference. My wife, brother-in-law, sister-in-law, cat, dog were all alive, I was not fully retired, hadn't had 3 serious operations, and Bush hadn't had a chance to do serious harm. -- [mail]: Chuck F (cbfalconer at maineline dot net) [page]: <http://cbfalconer.home.att.net> Try the download section. |
|
|
|
#18 |
|
Messages: n/a
Hébergeur: |
"CBFalconer" <cbfalconer@yahoo.com> wrote in message
news:488F732B.2D78A640@yahoo.com... > Nick Keighley wrote: > > CBFalconer <cbfalco...@yahoo.com> wrote: > >> Nick Keighleywrote: > > > >>> -- > >>> Nick Keighley > >> > >>> A lot of the c.l.c. verbiage seems to be devoted to the numerical > >>> density of cavorting nubile seraphim upon pinheads. > >>> CBFalconer > >> > >> Did I ever say that? I don't remember it. Seems accurate, though. > > > > It was from some time ago, but I *believe* I correctly attributed it. > > > > <google> > > > > yep, 2001-03-02 > > subject: "Sleep command for noninteger time" > > Oh my. Only 7 years ago, and what a difference. My wife, > brother-in-law, sister-in-law, cat, dog were all alive, I was not > fully retired, hadn't had 3 serious operations, and Bush hadn't had > a chance to do serious harm. Define Bush. ![]() |
|
|
|
#19 |
|
Messages: n/a
Hébergeur: |
"Ben Bacarisse" <ben.usenet@bsb.me.uk> wrote in message
news:87ej5f764i.fsf@bsb.me.uk... > "ArWeGod" <ArWeGod?@sbcglobal.net> writes: > > > "sophia" <sophia.agnes@gmail.com> wrote in message > > news:79d97bf1-4071-4637-934e-21428324a1b0@y22g2000prd.googlegroups.com... > >> Dear all, > >> > >> In C, x % y = ( x -(x/y) * y); is n't it ...???? where x and y are > >> integers and y not equal to zero > > > > WTF? x%y does not always equal zero. What use woudl that be?! > > The expression given is a C arithmetic expression. It is not intended > to be read as mathematics. Okay, I don't see how something arithmetic can avoid being mathematics, but let's push forward. All I see is X divided by Y, times Y (i.e. X, for those following along) subtracted from itself to acheive ZERO in 100% of the cases. So I guess I don't see how this works... Let's do the math (or arithmetic): 10 % 10 = 10 - ( (10/10, ie 1) * 10 (ie: back to 10)) = ZERO!!! Yay! 2 % 10 = 2 minus (2 divided by 10 times 10) = ? Anyone.... Anyone... -- ArWeConfused |
|
|
|
#20 |
|
Messages: n/a
Hébergeur: |
>> >> In C, x % y = ( x -(x/y) * y); is n't it ...???? where x and y are
>> >> integers and y not equal to zero >> > >> > WTF? x%y does not always equal zero. What use woudl that be?! >> >> The expression given is a C arithmetic expression. It is not intended >> to be read as mathematics. > >Okay, I don't see how something arithmetic can avoid being mathematics, but >let's push forward. The / in that expression is INTEGER DIVISION. An integer divided by an integer yields an integer result. >All I see is X divided by Y, times Y >(i.e. X, for those following along) That's true if you are doing your mathematics in reals, but not if you're doing it in integers. >subtracted from itself to acheive ZERO in 100% of the cases. So I guess I >don't see how this works... 15/10 in C is 1, not 1.5, since the result of dividing two integers is an integer. >Let's do the math (or arithmetic): > >10 % 10 = 10 - ( (10/10, ie 1) * 10 (ie: back to 10)) = ZERO!!! Yay! >2 % 10 = 2 minus (2 divided by 10 times 10) = ? >Anyone.... Anyone... 2/10 is zero. |
|
|
|
#21 |
|
Messages: n/a
Hébergeur: |
> 2/10 is zero.
Oh. Right. Carry on. -- ArWeWrong/ArWeNew=1 (cos it's TRUE!) |
|
|
|
#22 |
|
Messages: n/a
Hébergeur: |
On Jul 30, 10:18 am, gordonb.ed...@burditt.org (Gordon Burditt) wrote:
<snip> > 2/10 is zero. Please don't remove attributions. |
|
|
|
#23 |
|
Messages: n/a
Hébergeur: |
On Jul 30, 12:22 pm, "ArWeGod" <ArWeG...@sbcglobal.net> wrote:
> > 2/10 is zero. > > Oh. Right. Carry on. Please don't remove attributions. |
|
|
|
#24 |
|
Messages: n/a
Hébergeur: |
Hello Sophia, list
On Apr 25, 4:30 am, sophia <sophia.ag...@gmail.com> wrote: http://en.wikipedia.org/wiki/Operato...etic_operators http://en.wikipedia.org/wiki/Modulo_operation Regards Ccello By the way... CBFalconer, sorry about your wife, brother-in-law, sister-in-law, cat and dog. |
|
|
|
#25 |
|
Messages: n/a
Hébergeur: |
ArWeGod wrote:
> .... snip ... > > Let's do the math (or arithmetic): > > 10 % 10 = 10 - ( (10/10, ie 1) * 10 (ie: back to 10)) = ZERO!!! Yay! > 2 % 10 = 2 minus (2 divided by 10 times 10) = ? > Anyone.... Anyone... Using the usual integer arithmetic, 2 / 10 is unequivicably zero. After which zero times 10 remains zero, and that is the value of the expression. -- [mail]: Chuck F (cbfalconer at maineline dot net) [page]: <http://cbfalconer.home.att.net> Try the download section. |
|
![]() |
| Outils de la discussion | |
|
|