Re: [R] Integer division

2022-12-21 Thread Martin Maechler
> Richard O'Keefe > on Wed, 21 Dec 2022 16:44:51 +1300 writes: > Lack of consensus: I should mention Python's // operator, > which does flooring division. I should mention Common > Lisp, where (floor - -), (ceiling - -), (round - -), and > (truncate - -) all return a

Re: [R] Integer division

2022-12-20 Thread Richard O'Keefe
Lack of consensus: I should mention Python's // operator, which does flooring division. I should mention Common Lisp, where (floor - -), (ceiling - -), (round - -), and (truncate - -) all return a quotient and appropriate remainder. I should mention Smalltalk, where // and \\ are

Re: [R] Integer division

2022-12-20 Thread avi.e.gross
ent: Tuesday, December 20, 2022 1:53 AM To: Richard O'Keefe Cc: r-help@r-project.org Subject: Re: [R] Integer division Thanks Richard, the "rounding claim" was my mistake (as I replied to Martin), I should said "truncates toward zero" as you explain. However, my p

Re: [R] Integer division

2022-12-19 Thread Göran Broström
Thanks Richard, the "rounding claim" was my mistake (as I replied to Martin), I should said "truncates toward zero" as you explain. However, my point was that these two mathematical functions should be defined in the documentation, as you also say. And I was surprised that there is no

Re: [R] Integer division

2022-12-19 Thread Richard O'Keefe
The Fortran '08 standard says << One operand of type integer may be divided by another operand of type integer. Although the mathematical quotient of two integers is not necessarily an integer, Table 7.2 specifies that an expression involving the division operator with two operands of type integer

Re: [R] Integer division

2022-12-19 Thread Bert Gunter
"It would probably be helpful to add a short paragraph to ?Arithmetic about the fact that R's %% uses the "floored" version, as recommended by Donald Knuth and as documented on the above Wikipedia page." Agreed (who am I to disagree?!). But perhaps something simpler like: "a %% b must always

Re: [R] Integer division

2022-12-19 Thread Martin Maechler
> Jeff Newmiller > on Mon, 19 Dec 2022 08:37:32 -0800 writes: > See https://en.m.wikipedia.org/wiki/Modulo_operation, > Variants of the definition, esp the point that Knuth > recommended the floor definition. The behavior of %/% > follows from the definition of %%

Re: [R] Integer division

2022-12-19 Thread Jeff Newmiller
See https://en.m.wikipedia.org/wiki/Modulo_operation, Variants of the definition, esp the point that Knuth recommended the floor definition. The behavior of %/% follows from the definition of %% given the documented relation in ?Arithmetic. R is not obligated to repeat the mistakes of C or

Re: [R] Integer division

2022-12-19 Thread Bert Gunter
If R does exactly what it says it does, why are you surprised, whether or not that is what other languages do? (Please excuse my fractured English). (Note: -8 = 1 + 3*(-3) = (-8 %% 3) + 3 * (-8 %/% 3 ), exactly as the Help excerpt you cited says) Of course, one may always question the wisdom

Re: [R] Integer division

2022-12-19 Thread Göran Broström
Den 2022-12-19 kl. 15:41, skrev Martin Maechler: Göran Broström on Mon, 19 Dec 2022 14:22:00 +0100 writes: > I have a long vector x with five-digit codes where the > first digit of each is of special interest, so I extracted > them through >> y <- x %/% 1

Re: [R] Integer division

2022-12-19 Thread Martin Maechler
> Göran Broström > on Mon, 19 Dec 2022 14:22:00 +0100 writes: > I have a long vector x with five-digit codes where the > first digit of each is of special interest, so I extracted > them through >> y <- x %/% 1 > but to my surprise y contained the value -1

[R] Integer division

2022-12-19 Thread Göran Broström
I have a long vector x with five-digit codes where the first digit of each is of special interest, so I extracted them through > y <- x %/% 1 but to my surprise y contained the value -1 in some places. It turned out that x contains -1 as a symbol for 'missing value' so in effect I found