9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] More Microsoft bashing
@ 2005-12-16  4:04 Jack Johnson
  2005-12-16  4:51 ` Dan Cross
                   ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: Jack Johnson @ 2005-12-16  4:04 UTC (permalink / raw)
  To: 9fans

Not really, but all the talk about Singularity got me poking around
and I came across this:

------

How are the functions DIV and MOD defined?

The following answers are given by the Internal Working Document on
the Common Language Infrastructure (CLI).

result = value1 DIV value2 satisfies the following conditions:
|result| = |value1| / |value2|, and
sign(result) = +, if sign(value1) = sign(value2)
sign(result) = - , if sign(value1) # sign(value2)

result  = value1 MOD value2 satisfies the following conditions:
result = value1 - value2 * (value1 DIV value2), and
0 <= |result| < |value2|, and
sign(result) = sign(value1)

Please note that this definition of DIV and MOD differs from the
definition given in [M. Reiser, N. Wirth. Programming in Oberon. p.
36]:
x  = (x DIV y) * y + (x MOD y), and
0 <= (x MOD y) < y

( from http://www.bluebottle.ethz.ch/oberon.net/faq.html#ad_DivMod )

------

I kind of collect random, older computer science texts, so I cracked
open The Nature of Computation by Pohl and Shaw, which yields:

  "x MOD y = x - (x ÷ y) * y, where ÷ indicates integer division (i.e.
fractions are disregarded; equivalently, the result of the division is
truncated)."

So, what *is* -5 MOD 3?

-Jack


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [9fans] More Microsoft bashing
  2005-12-16  4:04 [9fans] More Microsoft bashing Jack Johnson
@ 2005-12-16  4:51 ` Dan Cross
  2005-12-16  5:02   ` Dan Cross
  2005-12-16  4:53 ` erik quanstrom
  2005-12-17 11:09 ` David Leimbach
  2 siblings, 1 reply; 24+ messages in thread
From: Dan Cross @ 2005-12-16  4:51 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Thu, Dec 15, 2005 at 08:04:02PM -0800, Jack Johnson wrote:
> So, what *is* -5 MOD 3?

Well, in general, it depends.

Do you care whether the result a set or an integer?  The definitions due
to Wirth et al are the former, while the MS definition appears to be the
latter.

Regardless, all these definitions are problematic.  No where does it say
they're defined only on Z*; what if Y is 0?

	- Dan C.



^ permalink raw reply	[flat|nested] 24+ messages in thread

* [9fans] More Microsoft bashing
  2005-12-16  4:04 [9fans] More Microsoft bashing Jack Johnson
  2005-12-16  4:51 ` Dan Cross
@ 2005-12-16  4:53 ` erik quanstrom
  2005-12-16  5:08   ` Dan Cross
  2005-12-16 10:47   ` John Stalker
  2005-12-17 11:09 ` David Leimbach
  2 siblings, 2 replies; 24+ messages in thread
From: erik quanstrom @ 2005-12-16  4:53 UTC (permalink / raw)
  To: 9fans, Jack Johnson

these can be shown to be the same:

Jack Johnson <knapjack@gmail.com> writes

| result  = value1 MOD value2 satisfies the following conditions:
| result = value1 - value2 * (value1 DIV value2), and
| 0 <= |result| < |value2|, and
| sign(result) = sign(value1)

but subsituting with wirth's eqn:
	
	r = x MOD y
thus
	(x MOD y) = x - y*(x DIV y)
so
	x = (x DIV y) + (x MOD y)

| 
| Please note that this definition of DIV and MOD differs from the
| definition given in [M. Reiser, N. Wirth. Programming in Oberon. p.
| 36]:
| x  = (x DIV y) * y + (x MOD y), and
| 0 <= (x MOD y) < y
| 
| ( from http://www.bluebottle.ethz.ch/oberon.net/faq.html#ad_DivMod )

| 
| ------
| 
| I kind of collect random, older computer science texts, so I cracked
| open The Nature of Computation by Pohl and Shaw, which yields:
| 
|   "x MOD y = x - (x ÷ y) * y, where ÷ indicates integer division (i.e.
| fractions are disregarded; equivalently, the result of the division is
| truncated)."

uh, if you replace ÷ with DIV (since the definition is the same),

	x MOD y = x - (x DIV y)*y
thus
	x  = (x DIV y) * y + (x MOD y)

| 
| So, what *is* -5 MOD 3?
| 

-2


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [9fans] More Microsoft bashing
  2005-12-16  4:51 ` Dan Cross
@ 2005-12-16  5:02   ` Dan Cross
  2005-12-16  5:33     ` erik quanstrom
  0 siblings, 1 reply; 24+ messages in thread
From: Dan Cross @ 2005-12-16  5:02 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Thu, Dec 15, 2005 at 11:51:15PM -0500, Dan Cross wrote:
> On Thu, Dec 15, 2005 at 08:04:02PM -0800, Jack Johnson wrote:
> > So, what *is* -5 MOD 3?
> 
> Well, in general, it depends.
> 
> Do you care whether the result a set or an integer?  The definitions due
> to Wirth et al are the former, while the MS definition appears to be the
> latter.

Hmm, I guess on further reflection I ought to explain what I mean by
this before someone jumps all over me.

The definition as per Wirth et al gives you a positive generator for an
equivalence class on Z, whereas the microsoft definition gives you the
definition of the division function extended to all of Z, which yields
an integer; the former definition is probably more comfortable for a
mathematician, and more what one would expect.  The latter is more
comfortable for someone who just wants to write a program.  In neither
case does this have much to do with the actual implementation (that is
to say, it's not like DIV actually gives you back an object
representing the set of all integers congruent to 0 modulo some integer
in Pascal), but only how that language interprets the definitions.

> Regardless, all these definitions are problematic.  No where does it say
> they're defined only on Z*; what if Y is 0?

This is still a problem.  You really want a function f: Z x Z* -> Z,
not f: Z x Z -> Z; that is, for f(x, y) = x div y, y should be non-zero.
Otherwise, it would be an absurdity.

	- Dan C.



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [9fans] More Microsoft bashing
  2005-12-16  4:53 ` erik quanstrom
@ 2005-12-16  5:08   ` Dan Cross
  2005-12-16  5:19     ` Brian L. Stuart
                       ` (2 more replies)
  2005-12-16 10:47   ` John Stalker
  1 sibling, 3 replies; 24+ messages in thread
From: Dan Cross @ 2005-12-16  5:08 UTC (permalink / raw)
  To: erik quanstrom, Fans of the OS Plan 9 from Bell Labs

On Thu, Dec 15, 2005 at 10:53:06PM -0600, erik quanstrom wrote:
> | Please note that this definition of DIV and MOD differs from the
> | definition given in [M. Reiser, N. Wirth. Programming in Oberon. p.
> | 36]:
> | x  = (x DIV y) * y + (x MOD y), and
> | 0 <= (x MOD y) < y
    ^^^^^^^^^^^^^^^^^^
> | 
> | So, what *is* -5 MOD 3?
> | 
> 
> -2

Are you sure?  It looks to me more than it'd be +1.  Wirth's definition
above would tend to indicate that x MOD y is always positive, unless I'm
reading it wrong, or that's not the whole story (and I confess I'm too
lazy to look up the definitions in context).  If I'm right, that would
also imply that x DIV y tends more wards negative infinity than zero
for negative numerators.

	- Dan C.



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [9fans] More Microsoft bashing
  2005-12-16  5:08   ` Dan Cross
@ 2005-12-16  5:19     ` Brian L. Stuart
  2005-12-16  5:27     ` Bruce Ellis
  2005-12-16 14:19     ` Brantley Coile
  2 siblings, 0 replies; 24+ messages in thread
From: Brian L. Stuart @ 2005-12-16  5:19 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

In message <20051216050830.GE15067@augusta.math.psu.edu>, Dan Cross writes:
>On Thu, Dec 15, 2005 at 10:53:06PM -0600, erik quanstrom wrote:
>> | Please note that this definition of DIV and MOD differs from the
>> | definition given in [M. Reiser, N. Wirth. Programming in Oberon. p.
>> | 36]:
>> | x  = (x DIV y) * y + (x MOD y), and
>> | 0 <= (x MOD y) < y
>    ^^^^^^^^^^^^^^^^^^
>> | 
>> | So, what *is* -5 MOD 3?
>> | 
>> 
>> -2
>
>Are you sure?  It looks to me more than it'd be +1.  Wirth's definition
>above would tend to indicate that x MOD y is always positive, unless I'm

This also matches Knuth's in Vol 1.  He states it as:

x mod y = x - y * floor( x / y )

and then observes that the mod follows the sign of y and that
the magnitude of the mod is strictly less than that of y.

Brian L. Stuart


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [9fans] More Microsoft bashing
  2005-12-16  5:08   ` Dan Cross
  2005-12-16  5:19     ` Brian L. Stuart
@ 2005-12-16  5:27     ` Bruce Ellis
  2005-12-16 14:19     ` Brantley Coile
  2 siblings, 0 replies; 24+ messages in thread
From: Bruce Ellis @ 2005-12-16  5:27 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

any C standard since forever has stated clearly that the
behaviour is undefined.  i've never written a program that
mods a negative number.  have fun in portability.

brucee

On 12/16/05, Dan Cross <cross@math.psu.edu> wrote:
> On Thu, Dec 15, 2005 at 10:53:06PM -0600, erik quanstrom wrote:
> > | Please note that this definition of DIV and MOD differs from the
> > | definition given in [M. Reiser, N. Wirth. Programming in Oberon. p.
> > | 36]:
> > | x  = (x DIV y) * y + (x MOD y), and
> > | 0 <= (x MOD y) < y
>    ^^^^^^^^^^^^^^^^^^
> > |
> > | So, what *is* -5 MOD 3?
> > |
> >
> > -2
>
> Are you sure?  It looks to me more than it'd be +1.  Wirth's definition
> above would tend to indicate that x MOD y is always positive, unless I'm
> reading it wrong, or that's not the whole story (and I confess I'm too
> lazy to look up the definitions in context).  If I'm right, that would
> also imply that x DIV y tends more wards negative infinity than zero
> for negative numerators.
>
>        - Dan C.
>
>


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [9fans] More Microsoft bashing
  2005-12-16  5:02   ` Dan Cross
@ 2005-12-16  5:33     ` erik quanstrom
  2005-12-16  5:38       ` Bruce Ellis
  2005-12-16 13:13       ` Dan Cross
  0 siblings, 2 replies; 24+ messages in thread
From: erik quanstrom @ 2005-12-16  5:33 UTC (permalink / raw)
  To: 9fans, Dan Cross

you've got to take you're math cap off, and put your cs cap on.

the motivation for defining MOD and DIV is so you can do somethign 
like this

	row = size  DIV columns
	col   = size MOD columns

the pseudo-mathematics is applied ex post facto. clearly you have to
get a single value out of the operation but that value is never going to
be a member of Z. it's going to be a n-bit binary integer. also,

; cat > /tmp/fu.c
int main(void){
	int x;

	x = 1 % 0;
}
/tmp/fu.c: In function `main':
/tmp/fu.c:4: warning: division by zero

- erik


Dan Cross <cross@math.psu.edu> writes

| 
| On Thu, Dec 15, 2005 at 11:51:15PM -0500, Dan Cross wrote:
| > On Thu, Dec 15, 2005 at 08:04:02PM -0800, Jack Johnson wrote:
| > > So, what *is* -5 MOD 3?
| > 
| > Well, in general, it depends.
| > 
| > Do you care whether the result a set or an integer?  The definitions due
| > to Wirth et al are the former, while the MS definition appears to be the
| > latter.
| 
| Hmm, I guess on further reflection I ought to explain what I mean by
| this before someone jumps all over me.
| 
| The definition as per Wirth et al gives you a positive generator for an
| equivalence class on Z, whereas the microsoft definition gives you the
| definition of the division function extended to all of Z, which yields
| an integer; the former definition is probably more comfortable for a
| mathematician, and more what one would expect.  The latter is more
| comfortable for someone who just wants to write a program.  In neither
| case does this have much to do with the actual implementation (that is
| to say, it's not like DIV actually gives you back an object
| representing the set of all integers congruent to 0 modulo some integer
| in Pascal), but only how that language interprets the definitions.
| 
| > Regardless, all these definitions are problematic.  No where does it say
| > they're defined only on Z*; what if Y is 0?
| 
| This is still a problem.  You really want a function f: Z x Z* -> Z,
| not f: Z x Z -> Z; that is, for f(x, y) = x div y, y should be non-zero.
| Otherwise, it would be an absurdity.
| 
| 	- Dan C.


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [9fans] More Microsoft bashing
  2005-12-16  5:33     ` erik quanstrom
@ 2005-12-16  5:38       ` Bruce Ellis
  2005-12-16 10:46         ` Charles Forsyth
  2005-12-16 13:13       ` Dan Cross
  1 sibling, 1 reply; 24+ messages in thread
From: Bruce Ellis @ 2005-12-16  5:38 UTC (permalink / raw)
  To: erik quanstrom, Fans of the OS Plan 9 from Bell Labs

horseshitt.  read.

brucee

On 12/16/05, erik quanstrom <quanstro@quanstro.net> wrote:
> you've got to take you're math cap off, and put your cs cap on.
>
> the motivation for defining MOD and DIV is so you can do somethign
> like this
>
>        row = size  DIV columns
>        col   = size MOD columns
>
> the pseudo-mathematics is applied ex post facto. clearly you have to
> get a single value out of the operation but that value is never going to
> be a member of Z. it's going to be a n-bit binary integer. also,
>
> ; cat > /tmp/fu.c
> int main(void){
>        int x;
>
>        x = 1 % 0;
> }
> /tmp/fu.c: In function `main':
> /tmp/fu.c:4: warning: division by zero
>
> - erik
>
>
> Dan Cross <cross@math.psu.edu> writes
>
> |
> | On Thu, Dec 15, 2005 at 11:51:15PM -0500, Dan Cross wrote:
> | > On Thu, Dec 15, 2005 at 08:04:02PM -0800, Jack Johnson wrote:
> | > > So, what *is* -5 MOD 3?
> | >
> | > Well, in general, it depends.
> | >
> | > Do you care whether the result a set or an integer?  The definitions due
> | > to Wirth et al are the former, while the MS definition appears to be the
> | > latter.
> |
> | Hmm, I guess on further reflection I ought to explain what I mean by
> | this before someone jumps all over me.
> |
> | The definition as per Wirth et al gives you a positive generator for an
> | equivalence class on Z, whereas the microsoft definition gives you the
> | definition of the division function extended to all of Z, which yields
> | an integer; the former definition is probably more comfortable for a
> | mathematician, and more what one would expect.  The latter is more
> | comfortable for someone who just wants to write a program.  In neither
> | case does this have much to do with the actual implementation (that is
> | to say, it's not like DIV actually gives you back an object
> | representing the set of all integers congruent to 0 modulo some integer
> | in Pascal), but only how that language interprets the definitions.
> |
> | > Regardless, all these definitions are problematic.  No where does it say
> | > they're defined only on Z*; what if Y is 0?
> |
> | This is still a problem.  You really want a function f: Z x Z* -> Z,
> | not f: Z x Z -> Z; that is, for f(x, y) = x div y, y should be non-zero.
> | Otherwise, it would be an absurdity.
> |
> |       - Dan C.
>


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [9fans] More Microsoft bashing
  2005-12-16  5:38       ` Bruce Ellis
@ 2005-12-16 10:46         ` Charles Forsyth
  0 siblings, 0 replies; 24+ messages in thread
From: Charles Forsyth @ 2005-12-16 10:46 UTC (permalink / raw)
  To: 9fans

it's an old argument and at one time the choice of definition was
almost a function of which side of the atlantic defined the language
or processor.

Ada compromised by providing both operations--
there's always room for one more--
calling them `mod' and `rem', with nothing left to chance.



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [9fans] More Microsoft bashing
  2005-12-16  4:53 ` erik quanstrom
  2005-12-16  5:08   ` Dan Cross
@ 2005-12-16 10:47   ` John Stalker
  2005-12-16 14:25     ` Brantley Coile
  2005-12-16 22:28     ` Victor Nazarov
  1 sibling, 2 replies; 24+ messages in thread
From: John Stalker @ 2005-12-16 10:47 UTC (permalink / raw)
  To: erik quanstrom, Fans of the OS Plan 9 from Bell Labs


> | 
> | So, what *is* -5 MOD 3?
> | 
> 
> -2

I hope not.  If you are really serious about using modular arithmetic
then you probably want to use something like PARI GP where -5 mod 3
is -5 mod 3, belonging to the data type of integers mod 3.  -2 mod 3
and 1 mod 3 are alternate representations of the same value.  If you
aren't serious about modular arithmetic and want the result to be an
integer then I think you are shooting yourself in the foot if you
implement it as anything other than -5 mod 3 == 1.  I want to be able
to test whether n is odd with `if ( n % 2 == 1 ) ...'  Of course, I'm
a mathematician rather than a CS person, but I think the other
convention has nothing to recommend it.
--
John Stalker
University of Dublin, Trinity College
School of Mathematics


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [9fans] More Microsoft bashing
  2005-12-16  5:33     ` erik quanstrom
  2005-12-16  5:38       ` Bruce Ellis
@ 2005-12-16 13:13       ` Dan Cross
  1 sibling, 0 replies; 24+ messages in thread
From: Dan Cross @ 2005-12-16 13:13 UTC (permalink / raw)
  To: erik quanstrom, Fans of the OS Plan 9 from Bell Labs

On Thu, Dec 15, 2005 at 11:33:46PM -0600, erik quanstrom wrote:
> you've got to take you're math cap off, and put your cs cap on.

This has nothing to do with it.  You're looking for a single definitive
definition of something that has no single definitive definition.

> the motivation for defining MOD and DIV is so you can do somethign 
> like this
> 
> 	row = size  DIV columns
> 	col   = size MOD columns

Well, one would hope so!  But then you have to wonder why `size' would
have occasion to be negative in such an example.  And even if it was,
why you couldn't work with absolute values and keep track of the signs
yourself.  Like what Bruce said.

> the pseudo-mathematics is applied ex post facto. clearly you have to
> get a single value out of the operation but that value is never going to
> be a member of Z. it's going to be a n-bit binary integer. also,

n-bit binary *integers* are members of Z (where Z is the set of all
integers: their representation doesn't matter).  But that's beside the
point.  In either case, you will get a single value back.  The question
is whether that value represents a congruence class or a single integer.
If you restrict your domain to non-negative integers, in this context,
it doesn't matter; you get something that's more or less the same thing
for your purposes.  If you allow negative integers, that's when the
differences become significant.  As Bruce said, I think it best to avoid
the situation.

> ; cat > /tmp/fu.c
> int main(void){
> 	int x;
> 
> 	x = 1 % 0;
> }
> /tmp/fu.c: In function `main':
> /tmp/fu.c:4: warning: division by zero

Well, at least one compiler is sane.

	- Dan C.



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [9fans] More Microsoft bashing
  2005-12-16  5:08   ` Dan Cross
  2005-12-16  5:19     ` Brian L. Stuart
  2005-12-16  5:27     ` Bruce Ellis
@ 2005-12-16 14:19     ` Brantley Coile
  2005-12-16 15:13       ` Bruce Ellis
  2 siblings, 1 reply; 24+ messages in thread
From: Brantley Coile @ 2005-12-16 14:19 UTC (permalink / raw)
  To: 9fans

	0 <= (x MOD y) < y  or  y < (x MOD y) <= 0
	
		-- `Programming in Oberon,' M. Reiser and N. Wirth, Page 36.
		(which is available as a pdf from the web)
		
> On Thu, Dec 15, 2005 at 10:53:06PM -0600, erik quanstrom wrote:
>> | Please note that this definition of DIV and MOD differs from the
>> | definition given in [M. Reiser, N. Wirth. Programming in Oberon. p.
>> | 36]:
>> | x  = (x DIV y) * y + (x MOD y), and
>> | 0 <= (x MOD y) < y
>     ^^^^^^^^^^^^^^^^^^
>> | 
>> | So, what *is* -5 MOD 3?
>> | 
>> 
>> -2
> 
> Are you sure?  It looks to me more than it'd be +1.  Wirth's definition
> above would tend to indicate that x MOD y is always positive, unless I'm
> reading it wrong, or that's not the whole story (and I confess I'm too
> lazy to look up the definitions in context).  If I'm right, that would
> also imply that x DIV y tends more wards negative infinity than zero
> for negative numerators.
> 
> 	- Dan C.



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [9fans] More Microsoft bashing
  2005-12-16 10:47   ` John Stalker
@ 2005-12-16 14:25     ` Brantley Coile
  2005-12-16 14:51       ` Gorka guardiola
  2005-12-16 22:28     ` Victor Nazarov
  1 sibling, 1 reply; 24+ messages in thread
From: Brantley Coile @ 2005-12-16 14:25 UTC (permalink / raw)
  To: 9fans

>  I want to be able
> to test whether n is odd with `if ( n % 2 == 1 ) ...'

I wonder if that is whay Wirth defined a function ODD(x) which
returns a boolean?



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [9fans] More Microsoft bashing
  2005-12-16 14:25     ` Brantley Coile
@ 2005-12-16 14:51       ` Gorka guardiola
  0 siblings, 0 replies; 24+ messages in thread
From: Gorka guardiola @ 2005-12-16 14:51 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

n & 1

On 12/16/05, Brantley Coile <brantley@coraid.com> wrote:
> >  I want to be able
> > to test whether n is odd with `if ( n % 2 == 1 ) ...'
>
> I wonder if that is whay Wirth defined a function ODD(x) which
> returns a boolean?
>
>


--
- curiosity sKilled the cat


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [9fans] More Microsoft bashing
  2005-12-16 14:19     ` Brantley Coile
@ 2005-12-16 15:13       ` Bruce Ellis
  2005-12-16 15:29         ` Russ Cox
  2005-12-16 15:33         ` Brantley Coile
  0 siblings, 2 replies; 24+ messages in thread
From: Bruce Ellis @ 2005-12-16 15:13 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Sorry - I thought we were talking about C.  Does plan9 have an
Oberon environment these days?

brucee

On 12/17/05, Brantley Coile <brantley@coraid.com> wrote:
>        0 <= (x MOD y) < y  or  y < (x MOD y) <= 0
>
>                -- `Programming in Oberon,' M. Reiser and N. Wirth, Page 36.
>                (which is available as a pdf from the web)
>
> > On Thu, Dec 15, 2005 at 10:53:06PM -0600, erik quanstrom wrote:
> >> | Please note that this definition of DIV and MOD differs from the
> >> | definition given in [M. Reiser, N. Wirth. Programming in Oberon. p.
> >> | 36]:
> >> | x  = (x DIV y) * y + (x MOD y), and
> >> | 0 <= (x MOD y) < y
> >     ^^^^^^^^^^^^^^^^^^
> >> |
> >> | So, what *is* -5 MOD 3?
> >> |
> >>
> >> -2
> >
> > Are you sure?  It looks to me more than it'd be +1.  Wirth's definition
> > above would tend to indicate that x MOD y is always positive, unless I'm
> > reading it wrong, or that's not the whole story (and I confess I'm too
> > lazy to look up the definitions in context).  If I'm right, that would
> > also imply that x DIV y tends more wards negative infinity than zero
> > for negative numerators.
> >
> >       - Dan C.
>
>


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [9fans] More Microsoft bashing
  2005-12-16 15:13       ` Bruce Ellis
@ 2005-12-16 15:29         ` Russ Cox
  2005-12-16 16:00           ` Bruce Ellis
  2005-12-16 15:33         ` Brantley Coile
  1 sibling, 1 reply; 24+ messages in thread
From: Russ Cox @ 2005-12-16 15:29 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> Sorry - I thought we were talking about C.  Does plan9 have an
> Oberon environment these days?

Actually, they were talking about Microsoft's CLI and Oberon.
You're the one who brought up C.

Russ


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [9fans] More Microsoft bashing
  2005-12-16 15:13       ` Bruce Ellis
  2005-12-16 15:29         ` Russ Cox
@ 2005-12-16 15:33         ` Brantley Coile
  1 sibling, 0 replies; 24+ messages in thread
From: Brantley Coile @ 2005-12-16 15:33 UTC (permalink / raw)
  To: 9fans

I was just trying to answer the observation that there was something
funny with Wirth's definition of MOD.  Which was, in fact, not his
definition.

And indeed I am working on a Plan 9 Oberon compiler, but don't hold your
breath.  It's getting few cycles.

I want it for embedded work, so I won't be doing the whole environment.
That's what acme is for.  :)

> Sorry - I thought we were talking about C.  Does plan9 have an
> Oberon environment these days?
> 
> brucee



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [9fans] More Microsoft bashing
  2005-12-16 15:29         ` Russ Cox
@ 2005-12-16 16:00           ` Bruce Ellis
  2005-12-17  0:26             ` Jack Johnson
  0 siblings, 1 reply; 24+ messages in thread
From: Bruce Ellis @ 2005-12-16 16:00 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Sorry for being relevant to the mailing list.

brucee

On 12/17/05, Russ Cox <rsc@swtch.com> wrote:
> > Sorry - I thought we were talking about C.  Does plan9 have an
> > Oberon environment these days?
>
> Actually, they were talking about Microsoft's CLI and Oberon.
> You're the one who brought up C.
>
> Russ


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [9fans] More Microsoft bashing
  2005-12-16 10:47   ` John Stalker
  2005-12-16 14:25     ` Brantley Coile
@ 2005-12-16 22:28     ` Victor Nazarov
  1 sibling, 0 replies; 24+ messages in thread
From: Victor Nazarov @ 2005-12-16 22:28 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

John Stalker wrote:

>>| 
>>| So, what *is* -5 MOD 3?
>>| 
>>
>>-2
>>    
>>
>
>I hope not.  If you are really serious about using modular arithmetic
>then you probably want to use something like PARI GP where -5 mod 3
>is -5 mod 3, belonging to the data type of integers mod 3.  -2 mod 3
>and 1 mod 3 are alternate representations of the same value.  If you
>aren't serious about modular arithmetic and want the result to be an
>integer then I think you are shooting yourself in the foot if you
>implement it as anything other than -5 mod 3 == 1.  I want to be able
>to test whether n is odd with `if ( n % 2 == 1 ) ...'  Of course, I'm
>a mathematician rather than a CS person, but I think the other
>convention has nothing to recommend it.
>
>  
>
Agreed on this. At least most (all I know) cryptography protocols 
require -5 mod 3 to be 1 for their implementations. At least lots of 
algorithms require ... == -5 mod 3 == -2 mod 3 == 1 mod 3 == 4 mod 3 == ....
--
Victor Nazarov
http://vir.comtv.ru/




^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [9fans] More Microsoft bashing
  2005-12-16 16:00           ` Bruce Ellis
@ 2005-12-17  0:26             ` Jack Johnson
  2005-12-17  3:59               ` Bruce Ellis
  0 siblings, 1 reply; 24+ messages in thread
From: Jack Johnson @ 2005-12-17  0:26 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On 12/16/05, Bruce Ellis <bruce.ellis@gmail.com> wrote:
> Sorry for being relevant to the mailing list.

And actually, I should probably apologize and clarify.  I didn't
intend to be irrelevant.  I wanted to bring it up because I had my own
expectations that turned out not to be true, and thought it might
foster good discussion regarding why it is the way it is in Plan 9 and
whether that was a conscious decision or legacy or something else.

Several people pointed out aspects of mod I hadn't considered--across
the spectrum--so I'm grateful.

-Jack


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [9fans] More Microsoft bashing
  2005-12-17  0:26             ` Jack Johnson
@ 2005-12-17  3:59               ` Bruce Ellis
  0 siblings, 0 replies; 24+ messages in thread
From: Bruce Ellis @ 2005-12-17  3:59 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Exactly.  If you really need to mod a neg you probably
have a bad algorithm.  If you need to you can do it
portably with a sign check.  If you want it to work
with more than one compiler you had better expect
the expected.  The result is undefined.  Ken took the
pragmatic approach.  So do others.

brucee

On 12/17/05, Jack Johnson <knapjack@gmail.com> wrote:
> On 12/16/05, Bruce Ellis <bruce.ellis@gmail.com> wrote:
> > Sorry for being relevant to the mailing list.
>
> And actually, I should probably apologize and clarify.  I didn't
> intend to be irrelevant.  I wanted to bring it up because I had my own
> expectations that turned out not to be true, and thought it might
> foster good discussion regarding why it is the way it is in Plan 9 and
> whether that was a conscious decision or legacy or something else.
>
> Several people pointed out aspects of mod I hadn't considered--across
> the spectrum--so I'm grateful.
>
> -Jack
>


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [9fans] More Microsoft bashing
  2005-12-16  4:04 [9fans] More Microsoft bashing Jack Johnson
  2005-12-16  4:51 ` Dan Cross
  2005-12-16  4:53 ` erik quanstrom
@ 2005-12-17 11:09 ` David Leimbach
  2005-12-17 11:24   ` David Leimbach
  2 siblings, 1 reply; 24+ messages in thread
From: David Leimbach @ 2005-12-17 11:09 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 1550 bytes --]

C's 'mod' isn't really mod.  It's actually remainder.  It's always been this
way to my knowledge.

If you want a real "mod" use Python or Ada :)

Dave

On 12/15/05, Jack Johnson <knapjack@gmail.com> wrote:
>
> Not really, but all the talk about Singularity got me poking around
> and I came across this:
>
> ------
>
> How are the functions DIV and MOD defined?
>
> The following answers are given by the Internal Working Document on
> the Common Language Infrastructure (CLI).
>
> result = value1 DIV value2 satisfies the following conditions:
> |result| = |value1| / |value2|, and
> sign(result) = +, if sign(value1) = sign(value2)
> sign(result) = - , if sign(value1) # sign(value2)
>
> result  = value1 MOD value2 satisfies the following conditions:
> result = value1 - value2 * (value1 DIV value2), and
> 0 <= |result| < |value2|, and
> sign(result) = sign(value1)
>
> Please note that this definition of DIV and MOD differs from the
> definition given in [M. Reiser, N. Wirth. Programming in Oberon. p.
> 36]:
> x  = (x DIV y) * y + (x MOD y), and
> 0 <= (x MOD y) < y
>
> ( from http://www.bluebottle.ethz.ch/oberon.net/faq.html#ad_DivMod )
>
> ------
>
> I kind of collect random, older computer science texts, so I cracked
> open The Nature of Computation by Pohl and Shaw, which yields:
>
>   "x MOD y = x - (x ÷ y) * y, where ÷ indicates integer division (i.e.
> fractions are disregarded; equivalently, the result of the division is
> truncated)."
>
> So, what *is* -5 MOD 3?
>
> -Jack
>

[-- Attachment #2: Type: text/html, Size: 1997 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [9fans] More Microsoft bashing
  2005-12-17 11:09 ` David Leimbach
@ 2005-12-17 11:24   ` David Leimbach
  0 siblings, 0 replies; 24+ messages in thread
From: David Leimbach @ 2005-12-17 11:24 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 2466 bytes --]

If you have the C99 standard handy anyway, this is clearly stated on page 82
:)

6.5.5.5:
---
The result of the / operator is the quotient from the division of the first
operand by the second; the result of the % operator is the remainder.  In
both operations, if the value of the second operand is zero, the behavior is
undefined.
---

So negatives are allowed in the C99 standard.

I don't have a copy of the C89 standard so I can't quote that one.  Plan 9 C
isn't C99 so I'm not sure any of this is even relevant ot the list.

In The C Programming Language ["draft ANSI Version" that I got from a
college professor who was retiring] it says that  the expression

x % y

produces the remainder when x is divided by y.


Dave

On 12/17/05, David Leimbach <leimy2k@gmail.com> wrote:
>
> C's 'mod' isn't really mod.  It's actually remainder.  It's always been
> this way to my knowledge.
>
> If you want a real "mod" use Python or Ada :)
>
> Dave
>
> On 12/15/05, Jack Johnson <knapjack@gmail.com> wrote:
> >
> > Not really, but all the talk about Singularity got me poking around
> > and I came across this:
> >
> > ------
> >
> > How are the functions DIV and MOD defined?
> >
> > The following answers are given by the Internal Working Document on
> > the Common Language Infrastructure (CLI).
> >
> > result = value1 DIV value2 satisfies the following conditions:
> > |result| = |value1| / |value2|, and
> > sign(result) = +, if sign(value1) = sign(value2)
> > sign(result) = - , if sign(value1) # sign(value2)
> >
> > result  = value1 MOD value2 satisfies the following conditions:
> > result = value1 - value2 * (value1 DIV value2), and
> > 0 <= |result| < |value2|, and
> > sign(result) = sign(value1)
> >
> > Please note that this definition of DIV and MOD differs from the
> > definition given in [M. Reiser, N. Wirth. Programming in Oberon. p.
> > 36]:
> > x  = (x DIV y) * y + (x MOD y), and
> > 0 <= (x MOD y) < y
> >
> > ( from http://www.bluebottle.ethz.ch/oberon.net/faq.html#ad_DivMod )
> >
> > ------
> >
> > I kind of collect random, older computer science texts, so I cracked
> > open The Nature of Computation by Pohl and Shaw, which yields:
> >
> >   "x MOD y = x - (x ÷ y) * y, where ÷ indicates integer division (i.e.
> > fractions are disregarded; equivalently, the result of the division is
> > truncated)."
> >
> > So, what *is* -5 MOD 3?
> >
> > -Jack
> >
>
>

[-- Attachment #2: Type: text/html, Size: 3378 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2005-12-17 11:24 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-16  4:04 [9fans] More Microsoft bashing Jack Johnson
2005-12-16  4:51 ` Dan Cross
2005-12-16  5:02   ` Dan Cross
2005-12-16  5:33     ` erik quanstrom
2005-12-16  5:38       ` Bruce Ellis
2005-12-16 10:46         ` Charles Forsyth
2005-12-16 13:13       ` Dan Cross
2005-12-16  4:53 ` erik quanstrom
2005-12-16  5:08   ` Dan Cross
2005-12-16  5:19     ` Brian L. Stuart
2005-12-16  5:27     ` Bruce Ellis
2005-12-16 14:19     ` Brantley Coile
2005-12-16 15:13       ` Bruce Ellis
2005-12-16 15:29         ` Russ Cox
2005-12-16 16:00           ` Bruce Ellis
2005-12-17  0:26             ` Jack Johnson
2005-12-17  3:59               ` Bruce Ellis
2005-12-16 15:33         ` Brantley Coile
2005-12-16 10:47   ` John Stalker
2005-12-16 14:25     ` Brantley Coile
2005-12-16 14:51       ` Gorka guardiola
2005-12-16 22:28     ` Victor Nazarov
2005-12-17 11:09 ` David Leimbach
2005-12-17 11:24   ` David Leimbach

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).