Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Kleuske <kleuske@nowhere.net> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: C arithmetic question. |
| Date | 2012-01-24 20:26 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <jfn46h$1c5$3@dont-email.me> (permalink) |
| References | (9 earlier) <0cd427df-7380-4af4-9b20-eef98dfd57a3@pt5g2000pbb.googlegroups.com> <4F1EF731.80107@verizon.net> <cebb0677-e7b3-4c02-82c8-81ab679d3c03@v6g2000pba.googlegroups.com> <4F1F07FF.3010001@verizon.net> <a52b651f-d69e-43d5-8ef1-ea4e2bd191a1@i10g2000pbl.googlegroups.com> |
On Tue, 24 Jan 2012 12:02:29 -0800, Chad saw fit to publish the following: > On Jan 24, 11:35 am, James Kuyper <jameskuy...@verizon.net> wrote: >> On 01/24/2012 01:40 PM, Chad wrote: >> >> > On Jan 24, 10:23 am, James Kuyper <jameskuy...@verizon.net> wrote: >> >> On 01/24/2012 01:03 PM, Chad wrote: >> ... >> >>> And for whatever reasons, it just appeared to me that this math >> >>> definition applied to this particular situation. >> >> >> Well, it doesn't. ULONG_MAX-57 is positive, so rules covering >> >> negative numbers aren't relevant. >> >> > Yes. This is why I said for this particular case. >> >> Which is "this particular case" if it doesn't involve ULONG_MAX-57? >> >> >> More importantly, the C standard mandates that integer division must >> >> truncate the value, removing the fractional part, so (-11)/3 must be >> >> truncated to -3, not rounded downward to -4. In combination with the >> >> requirement that (a/b)*b+a%b == a, that means that (-11)%3 must give >> >> a value of -2, not 1.- Hide quoted text - >> >> > What I'm trying to get at is that this math defintion seems to apply >> > to Michael's case and not the case in general. >> >> OK - I'm confused. What do you think Michael's case is? I thought it >> was (ULONG_MAX-57)%37. >> >> Alternatively, you could be referring to the case he mistakenly thought >> was relevant, (-58)%37? C requires a value of -21 for that case, while >> the rule you describe requires 16. However, both of those values >> satisfy the criterion he complained about being violated: >> >> > x = y (mod m) if and only if x - y is divisible by m. >> >> -58 - (-21) = -37 == -1*37 >> -58 - (16) = -74 == -2*37 >> >> So the issue you raise is irrelevant to his complaint. > > I'm going to sidestep your question for a minute... > > I interpret something like a = mq + r as being equivalent to > > a mod m = r > > This means that Michael's example becomes > > -58 % 37 = r > > -58 = 37q + r > > if the remainder is allowed to be negative, this expression could become > something like > > -58 = 37 * (-1) + (-21) > > > However, you clearly showed that the correct answer is.. > > 4294967238 = 116081095*37 + 23. > > > This in turn would lead me to believe there is the additional > restriction to the math forumla (definition) that the remainder has to > be positive. Problem is here are several definitions of the modulo operation. They all agree on what happens when operands are positive, but disagree what happens when one of the operands is negative. I'm not a standards-jockey, but i'd be interested what the experts have to say. See also http://en.wikipedia.org/wiki/Modulo_operator -- No problem is insoluble. -- Dr. Janet Wallace, "The Deadly Years", stardate 3479.4
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
C arithmetic question. Michael Press <rubrum@pacbell.net> - 2012-01-18 10:32 -0800
Re: C arithmetic question. James Kuyper <jameskuyper@verizon.net> - 2012-01-18 14:03 -0500
Re: C arithmetic question. TheGunslinger <mikiesrunsbaal.sec@sbcglobal.net> - 2012-01-18 19:30 -0800
Re: C arithmetic question. James Kuyper <jameskuyper@verizon.net> - 2012-01-19 08:10 -0500
Re: C arithmetic question. Markus Wichmann <nullplan@gmx.net> - 2012-01-18 21:14 +0100
Re: C arithmetic question. "BartC" <bc@freeuk.com> - 2012-01-19 10:44 +0000
Re: C arithmetic question. Seebs <usenet-nospam@seebs.net> - 2012-01-21 21:32 +0000
Re: C arithmetic question. Peter Nilsson <airia@acay.com.au> - 2012-01-18 13:51 -0800
Re: C arithmetic question. Michael Press <rubrum@pacbell.net> - 2012-01-18 15:51 -0800
Re: C arithmetic question. James Kuyper <jameskuyper@verizon.net> - 2012-01-18 20:50 -0500
Re: C arithmetic question. Michael Press <rubrum@pacbell.net> - 2012-01-20 12:41 -0800
Re: C arithmetic question. Keith Thompson <kst-u@mib.org> - 2012-01-20 14:11 -0800
Re: C arithmetic question. gazelle@shell.xmission.com (Kenny McCormack) - 2012-01-20 22:43 +0000
Re: C arithmetic question. James Kuyper <jameskuyper@verizon.net> - 2012-01-20 17:19 -0500
Re: C arithmetic question. James Kuyper <jameskuyper@verizon.net> - 2012-01-20 17:32 -0500
And jacob navia <jacob@spamsink.net> - 2012-01-20 23:52 +0100
Re: And Markus Wichmann <nullplan@gmx.net> - 2012-01-21 19:23 +0100
Re: And Keith Thompson <kst-u@mib.org> - 2012-01-21 13:20 -0800
Re: And jacob navia <jacob@spamsink.net> - 2012-01-21 23:02 +0100
Re: And Markus Wichmann <nullplan@gmx.net> - 2012-01-22 15:24 +0100
Re: And Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-22 15:40 +0000
Re: And blp@cs.stanford.edu (Ben Pfaff) - 2012-01-21 11:02 -0800
Re: C arithmetic question. Rui Maciel <rui.maciel@gmail.com> - 2012-01-24 18:53 +0000
Re: C arithmetic question. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-19 02:09 +0000
Re: C arithmetic question. Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2012-01-18 23:00 -0700
Re: C arithmetic question. Michael Press <rubrum@pacbell.net> - 2012-01-18 23:14 -0800
Re: C arithmetic question. Ike Naar <ike@sverige.freeshell.org> - 2012-01-19 08:41 +0000
Re: C arithmetic question. Michael Press <rubrum@pacbell.net> - 2012-01-20 12:43 -0800
Re: C arithmetic question. Kaz Kylheku <kaz@kylheku.com> - 2012-01-20 22:17 +0000
Re: C arithmetic question. Michael Press <rubrum@pacbell.net> - 2012-01-21 00:12 -0800
Re: C arithmetic question. Seebs <usenet-nospam@seebs.net> - 2012-01-21 21:32 +0000
Re: C arithmetic question. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-21 23:21 +0000
Re: C arithmetic question. Robert Wessel <robertwessel2@yahoo.com> - 2012-01-22 00:48 -0600
Re: C arithmetic question. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-22 11:45 +0000
Re: C arithmetic question. Robert Wessel <robertwessel2@yahoo.com> - 2012-01-22 21:46 -0600
Re: C arithmetic question. Kaz Kylheku <kaz@kylheku.com> - 2012-01-23 04:17 +0000
Re: C arithmetic question. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-23 11:19 +0000
Re: C arithmetic question. Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-26 10:41 -0800
Re: C arithmetic question. Seebs <usenet-nospam@seebs.net> - 2012-01-23 07:58 +0000
Re: C arithmetic question. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-23 11:06 +0000
Re: C arithmetic question. James Kuyper <jameskuyper@verizon.net> - 2012-01-23 07:03 -0500
Re: C arithmetic question. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-23 17:27 +0000
Re: C arithmetic question. Keith Thompson <kst-u@mib.org> - 2012-01-19 02:38 -0800
Re: C arithmetic question. Dr Nick <3-nospam@temporary-address.org.uk> - 2012-01-20 07:30 +0000
Re: C arithmetic question. Nomen Nescio <nobody@dizum.com> - 2012-01-19 12:28 +0100
Re: C arithmetic question. Michael Press <rubrum@pacbell.net> - 2012-01-20 12:44 -0800
Re: C arithmetic question. 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-20 13:14 -0800
Re: C arithmetic question. James Kuyper <jameskuyper@verizon.net> - 2012-01-19 08:45 -0500
Re: C arithmetic question. Chad <cdalten@gmail.com> - 2012-01-24 08:14 -0800
Re: C arithmetic question. James Kuyper <jameskuyper@verizon.net> - 2012-01-24 12:15 -0500
Re: C arithmetic question. Chad <cdalten@gmail.com> - 2012-01-24 09:26 -0800
Re: C arithmetic question. James Kuyper <jameskuyper@verizon.net> - 2012-01-24 12:39 -0500
Re: C arithmetic question. Chad <cdalten@gmail.com> - 2012-01-24 10:03 -0800
Re: C arithmetic question. James Kuyper <jameskuyper@verizon.net> - 2012-01-24 13:23 -0500
Re: C arithmetic question. Chad <cdalten@gmail.com> - 2012-01-24 10:40 -0800
Re: C arithmetic question. James Kuyper <jameskuyper@verizon.net> - 2012-01-24 14:35 -0500
Re: C arithmetic question. Chad <cdalten@gmail.com> - 2012-01-24 12:04 -0800
Re: C arithmetic question. Chad <cdalten@gmail.com> - 2012-01-24 12:02 -0800
Re: C arithmetic question. Kleuske <kleuske@nowhere.net> - 2012-01-24 20:26 +0000
Re: C arithmetic question. Chad <cdalten@gmail.com> - 2012-01-24 13:45 -0800
Re: C arithmetic question. James Kuyper <jameskuyper@verizon.net> - 2012-01-24 15:40 -0500
Re: C arithmetic question. Chad <cdalten@gmail.com> - 2012-01-24 12:09 -0800
Re: C arithmetic question. Rui Maciel <rui.maciel@gmail.com> - 2012-01-24 18:48 +0000
Re: C arithmetic question. "osmium" <r124c4u102@comcast.net> - 2012-01-19 08:12 -0600
Re: C arithmetic question. Geoff <geoff@invalid.invalid> - 2012-01-20 15:33 -0800
Re: C arithmetic question. Kleuske <kleuske@nowhere.net> - 2012-01-27 08:17 +0000
Re: C arithmetic question. Geoff <geoff@invalid.invalid> - 2012-01-27 13:37 -0800
csiph-web