Re: Mod (%) function in C/Objective-C?

2014-08-12 Thread Dave
On 12 Aug 2014, at 00:41, Keary Suska cocoa-...@esoteritech.com wrote: On Aug 11, 2014, at 2:52 PM, Dave d...@looktowindward.com wrote: On 10 Aug 2014, at 16:16, Keary Suska cocoa-...@esoteritech.com wrote: I don't think so, although I would expect a C lib somewhere to address it.

Re: Mod (%) function in C/Objective-C?

2014-08-12 Thread Keary Suska
On Aug 12, 2014, at 1:42 AM, Dave d...@looktowindward.com wrote: Maybe my brain isn't working correctly but that doesn't make sense to me. Could you show the output with both x and y shown? Now, you aren't dividing by a negative integer, are you? I believe that is undefined… Yes, it's my

Re: Mod (%) function in C/Objective-C?

2014-08-12 Thread Dave
On 12 Aug 2014, at 15:01, Keary Suska cocoa-...@esoteritech.com wrote: On Aug 12, 2014, at 1:42 AM, Dave d...@looktowindward.com wrote: Maybe my brain isn't working correctly but that doesn't make sense to me. Could you show the output with both x and y shown? Now, you aren't dividing

Re: Mod (%) function in C/Objective-C?

2014-08-12 Thread Scott Ribe
On Aug 12, 2014, at 10:01 AM, Dave d...@looktowindward.com wrote: I’m not sure what you mean by dividing by a negative number is undefined? It sure as hell better be defined, hadn't it? We wouldn't want a language where the basic math ops were that foobar'd! Now in KR C, the direction of

Re: Mod (%) function in C/Objective-C?

2014-08-12 Thread Dave
On 12 Aug 2014, at 17:11, Scott Ribe scott_r...@elevated-dev.com wrote: On Aug 12, 2014, at 10:01 AM, Dave d...@looktowindward.com wrote: I’m not sure what you mean by dividing by a negative number is undefined? It sure as hell better be defined, hadn't it? We wouldn't want a language

Re: Mod (%) function in C/Objective-C?

2014-08-12 Thread Steve Sisak
At 3:24 PM -0600 8/11/14, Scott Ribe wrote: On Aug 11, 2014, at 3:03 PM, Dave d...@looktowindward.com wrote: The first edition of KR mistakenly referred to it as modulus (apparently based on the PDP-11 instruction which was similarly misnamed). When in doubt, remember what C was designed to

Re: Mod (%) function in C/Objective-C?

2014-08-12 Thread Keary Suska
On Aug 12, 2014, at 10:17 AM, Dave d...@looktowindward.com wrote: On 12 Aug 2014, at 17:11, Scott Ribe scott_r...@elevated-dev.com wrote: On Aug 12, 2014, at 10:01 AM, Dave d...@looktowindward.com wrote: I’m not sure what you mean by dividing by a negative number is undefined? It

Re: Mod (%) function in C/Objective-C?

2014-08-11 Thread Dave
On 10 Aug 2014, at 16:16, Keary Suska cocoa-...@esoteritech.com wrote: I don't think so, although I would expect a C lib somewhere to address it. Anyway, isn't easier to just always abs(x)%y? abs(x)%y Doesn’t give the same result: myIndex: -5 myMod: 1 abs(x)%y: 2 myIndex: -4

Re: Mod (%) function in C/Objective-C?

2014-08-11 Thread Dave
On 10 Aug 2014, at 17:04, Scott Ribe scott_r...@elevated-dev.com wrote: On Aug 10, 2014, at 9:16 AM, Keary Suska cocoa-...@esoteritech.com wrote: I don't think so, although I would expect a C lib somewhere to address it. I think the standard C libs only have floating-point versions of mod

Re: Mod (%) function in C/Objective-C?

2014-08-11 Thread koko
In computing, the modulo (sometimes called modulus) operation finds the remainder of division of one number by another. Given two positive numbers, a (the dividend) and n (the divisor), a modulo n (abbreviated as a mod n) is the remainder of theEuclidean division of a by n. For instance, the

Re: Mod (%) function in C/Objective-C?

2014-08-11 Thread Scott Ribe
On Aug 11, 2014, at 3:03 PM, Dave d...@looktowindward.com wrote: My conclusion is (a % b) in C is a remainder operator and NOT modulo operator. Yes. The first edition of KR mistakenly referred to it as modulus (apparently based on the PDP-11 instruction which was similarly misnamed). The

Re: Mod (%) function in C/Objective-C?

2014-08-11 Thread Scott Ribe
On Aug 11, 2014, at 3:15 PM, koko k...@highrolls.net wrote: When either a or n is negative, the naive definition breaks down and programming languages differ in how these values are defined. But that is only because what you call the naive definition is incorrect. The actual definition is

Re: Mod (%) function in C/Objective-C?

2014-08-11 Thread Dave
On 11 Aug 2014, at 22:15, koko k...@highrolls.net wrote: In computing, the modulo (sometimes called modulus) operation finds the remainder of division of one number by another. Given two positive numbers, a (the dividend) and n (the divisor), a modulo n (abbreviated as a mod n) is the

Re: Mod (%) function in C/Objective-C?

2014-08-11 Thread Dave
On 11 Aug 2014, at 22:24, Scott Ribe scott_r...@elevated-dev.com wrote: On Aug 11, 2014, at 3:03 PM, Dave d...@looktowindward.com wrote: My conclusion is (a % b) in C is a remainder operator and NOT modulo operator. Yes. The first edition of KR mistakenly referred to it as modulus

Re: Mod (%) function in C/Objective-C?

2014-08-11 Thread Dave
On 11 Aug 2014, at 22:26, Scott Ribe scott_r...@elevated-dev.com wrote: On Aug 11, 2014, at 3:15 PM, koko k...@highrolls.net wrote: When either a or n is negative, the naive definition breaks down and programming languages differ in how these values are defined. But that is only because

Re: Mod (%) function in C/Objective-C?

2014-08-11 Thread Keary Suska
On Aug 11, 2014, at 2:52 PM, Dave d...@looktowindward.com wrote: On 10 Aug 2014, at 16:16, Keary Suska cocoa-...@esoteritech.com wrote: I don't think so, although I would expect a C lib somewhere to address it. Anyway, isn't easier to just always abs(x)%y? abs(x)%y Doesn’t give

Mod (%) function in C/Objective-C?

2014-08-10 Thread Dave
Hi, I just got caught out by the C/Objective-C Implementation of the % (mod) function in XCode C/Objective-C. I remember having this very same problem years ago (after I solved it again this time). It stems from the modulus (%) function not returning a true modulus for negative numbers

Re: Mod (%) function in C/Objective-C?

2014-08-10 Thread Keary Suska
On Aug 10, 2014, at 6:31 AM, Dave d...@looktowindward.com wrote: I just got caught out by the C/Objective-C Implementation of the % (mod) function in XCode C/Objective-C. I remember having this very same problem years ago (after I solved it again this time). It stems from the modulus

Re: Mod (%) function in C/Objective-C?

2014-08-10 Thread Scott Ribe
On Aug 10, 2014, at 9:16 AM, Keary Suska cocoa-...@esoteritech.com wrote: I don't think so, although I would expect a C lib somewhere to address it. I think the standard C libs only have floating-point versions of mod functions. (That does seem like an odd omission.) This would at least be a