Re: Question about slight deviations when using integer division with large integers.

2018-12-31 Thread Christian Seberino
Thanks to all who helped. As was previously pointed out, many other languages use truncation rather than rounding for // division. Getting the behavior you want may be as easy as replacing // with the int() function >>> x = 9 ; y = 2 >>> x // y, -x // y, (-x) // y (4, -5, -5) >>> int(x /

Re: Question about slight deviations when using integer division with large integers.

2018-12-31 Thread Paul Moore
On Mon, 31 Dec 2018 at 09:00, Christian Seberino wrote: > > Thanks. I didn’t post new code. I was just referring back to original > post. I need to duplicate the exact behavior of Java’s BigIntegers. > > I’m guessing difference between Java and Python is that Java BigIntegers do > not switch to

Re: Question about slight deviations when using integer division with large integers.

2018-12-31 Thread Cameron Simpson
On 30Dec2018 23:33, Christian Seberino wrote: Thanks. I didn’t post new code. I was just referring back to original post. I think Ian looked up the first post on Google Groups, where your code was evident. The message was incomplete when it got here (the mailing list); I don't know why.

Re: Question about slight deviations when using integer division with large integers.

2018-12-31 Thread Christian Seberino
Thanks. I didn’t post new code. I was just referring back to original post. I need to duplicate the exact behavior of Java’s BigIntegers. I’m guessing difference between Java and Python is that Java BigIntegers do not switch to floor for negatives. Possible to tweak rounding of Python to be li

Question about slight deviations when using integer division with large integers.

2018-12-31 Thread Christian Seberino
Why are the following two similar prints slightly different and how fix? >>> x = 0x739ad43ed636 >>> print(x + (-x) // 2048) 127046758190683 >>> print(x - x // 2048) 127046758190684 I'm working in an area where such deviations matter. It would nice to understand what is happening. Any help

Re: Question about slight deviations when using integer division with large integers.

2018-12-30 Thread Ian Kelly
way-to-round-towards-zero-in-integer-division -- https://mail.python.org/mailman/listinfo/python-list

Re: Question about slight deviations when using integer division with large integers.

2018-12-30 Thread Chris Angelico
On Mon, Dec 31, 2018 at 6:36 PM Ian Kelly wrote: > > The Google group has an initial post in this thread that didn't make it > through to the mailing list for whatever reason. For posterity, here > it is: Thanks Ian. > > Why are the following two similar prints slightly different and how fix? >

Re: Question about slight deviations when using integer division with large integers.

2018-12-30 Thread Ian Kelly
On Sun, Dec 30, 2018 at 10:27 PM Cameron Simpson wrote: > > On 30Dec2018 21:14, Christian Seberino wrote: > >What is simplest way to make both those > >prints give same values? Any slicker way > >than an if statement? > > If your post had an attachment, be aware that the python-list list drops >

Re: Question about slight deviations when using integer division with large integers.

2018-12-30 Thread Cameron Simpson
On 30Dec2018 21:14, Christian Seberino wrote: What is simplest way to make both those prints give same values? Any slicker way than an if statement? If your post had an attachment, be aware that the python-list list drops all attachments - it is a text only list. Please paste your code dire

Re: Question about slight deviations when using integer division with large integers.

2018-12-30 Thread Christian Seberino
What is simplest way to make both those prints give same values? Any slicker way than an if statement? -- https://mail.python.org/mailman/listinfo/python-list

Re: Question about slight deviations when using integer division with large integers.

2018-12-30 Thread Chris Angelico
On Mon, Dec 31, 2018 at 1:56 PM Christian Seberino wrote: > > Perhaps the "secret" is *not* do integer division with negative numbers? I have no idea what you're replying to, but integer division with negative numbers IS well defined. Python will floor - it will alway

Re: Question about slight deviations when using integer division with large integers.

2018-12-30 Thread Christian Seberino
Perhaps the "secret" is *not* do integer division with negative numbers? -- https://mail.python.org/mailman/listinfo/python-list

Re: How to simulate C style integer division?

2016-01-23 Thread Grobu
On 23/01/16 16:07, Jussi Piitulainen wrote: Grobu writes: def intdiv(a, b): return (a - (a % (-b if a < 0 else b))) / b Duh ... Got confused with modulos (again). def intdiv(a, b): return (a - (a % (-abs(b) if a < 0 else abs(b / b You should use // here to get an exact int

Re: How to simulate C style integer division?

2016-01-23 Thread Jussi Piitulainen
Grobu writes: >> def intdiv(a, b): >> return (a - (a % (-b if a < 0 else b))) / b >> >> > > Duh ... Got confused with modulos (again). > > def intdiv(a, b): > return (a - (a % (-abs(b) if a < 0 else abs(b / b You should use // here to get an exact integer result. -- https://mail.pyt

Re: How to simulate C style integer division?

2016-01-23 Thread Grobu
def intdiv(a, b): return (a - (a % (-b if a < 0 else b))) / b Duh ... Got confused with modulos (again). def intdiv(a, b): return (a - (a % (-abs(b) if a < 0 else abs(b / b -- https://mail.python.org/mailman/listinfo/python-list

Re: How to simulate C style integer division?

2016-01-23 Thread Grobu
rror: long int too large to convert to float Note that Python gets the integer division correct: py> a//b 2L And even gets true division correct: py> from __future__ import division py> a/b 2.0 so it's just the intermediate conversion to float that fails. Thanks! I d

Re: How to simulate C style integer division?

2016-01-21 Thread Random832
Terry Reedy writes: > But fails with remainder 0, as others noted. Lesson: include corner > cases in validation test. Anyway, my main point about writing a clear > spec remains true. My validation test for this was to loop both numerator and denominator from -5 to 5 (skipping denominator 0) to

Re: How to simulate C style integer division?

2016-01-21 Thread Steven D'Aprano
On Fri, 22 Jan 2016 12:59 pm, Grobu wrote: > On 21/01/16 09:39, Shiyao Ma wrote: >> Hi, >> >> I wanna simulate C style integer division in Python3. >> >> So far what I've got is: >> # a, b = 3, 4 >> >> import math >> result = f

Re: How to simulate C style integer division?

2016-01-21 Thread Terry Reedy
On 1/21/2016 9:56 PM, Terry Reedy wrote: On 1/21/2016 3:39 AM, Shiyao Ma wrote: I wanna simulate C style integer division in Python3. There are two problems with this spec: it assumes that 'C style integer division' is well defined and that we know the definition. Better: "H

Re: How to simulate C style integer division?

2016-01-21 Thread Terry Reedy
On 1/21/2016 3:39 AM, Shiyao Ma wrote: I wanna simulate C style integer division in Python3. There are two problems with this spec: it assumes that 'C style integer division' is well defined and that we know the definition. Better: "How do I write a function 'div'

Re: How to simulate C style integer division?

2016-01-21 Thread Grobu
On 21/01/16 09:39, Shiyao Ma wrote: Hi, I wanna simulate C style integer division in Python3. So far what I've got is: # a, b = 3, 4 import math result = float(a) / b if result > 0: result = math.floor(result) else: result = math.ceil(result) I found it's too laborious.

Re: How to simulate C style integer division?

2016-01-21 Thread Matt Wheeler
On 21 January 2016 at 21:17, Marko Rauhamaa wrote: > Well, then there's: > > def intdiv(a, b): > return int(a / b) That depends on how accurate you need it to be >>> def intdiv(a, b): ... return a//b if (a < 0) == (b < 0) else -(-a//b) ... >>> num = 3**171 >>> num 387021023451030799

Re: How to simulate C style integer division?

2016-01-21 Thread Marko Rauhamaa
Random832 : > On Thu, Jan 21, 2016, at 09:31, Marko Rauhamaa wrote: >> Maybe: >> >>def intdiv(a, b): >>return a // b if (a < 0) == (b < 0) else -(-a // b) > > Personally, I like a // b + (a % b and a ^ b < 0) - I've done the > opposite in C to get python-style division. Well, then th

Re: How to simulate C style integer division?

2016-01-21 Thread Random832
On Thu, Jan 21, 2016, at 09:31, Marko Rauhamaa wrote: > Maybe: > >def intdiv(a, b): >return a // b if (a < 0) == (b < 0) else -(-a // b) Personally, I like a // b + (a % b and a ^ b < 0) - I've done the opposite in C to get python-style division. -- https://mail.python.org/mailman/li

Re: How to simulate C style integer division?

2016-01-21 Thread Jussi Piitulainen
Marko Rauhamaa writes: > Jussi Piitulainen writes: > >> Steven D'Aprano writes: >> >>> So my guess is that the fastest, and certainly the most obvious, way >>> to get the same integer division behaviour as C99 would be: >>> >>>

Re: How to simulate C style integer division?

2016-01-21 Thread Marko Rauhamaa
Jussi Piitulainen : > Steven D'Aprano writes: > >> So my guess is that the fastest, and certainly the most obvious, way >> to get the same integer division behaviour as C99 would be: >> >> def intdiv(a, b): >> # C99 style integer division with

Re: How to simulate C style integer division?

2016-01-21 Thread Wolfgang Maier
On 1/21/2016 15:00, Jussi Piitulainen wrote: Steven D'Aprano writes: So my guess is that the fastest, and certainly the most obvious, way to get the same integer division behaviour as C99 would be: def intdiv(a, b): # C99 style integer division with truncation towards zero. n =

Re: How to simulate C style integer division?

2016-01-21 Thread Jussi Piitulainen
Steven D'Aprano writes: > So my guess is that the fastest, and certainly the most obvious, way > to get the same integer division behaviour as C99 would be: > > def intdiv(a, b): > # C99 style integer division with truncation towards zero. > n = a//b >

Re: How to simulate C style integer division?

2016-01-21 Thread Steven D'Aprano
On Thu, 21 Jan 2016 08:11 pm, Ben Finney wrote: > Shiyao Ma writes: > >> I wanna simulate C style integer division in Python3. > > I'm not sure I know exactly what behaviour you want (“C style” may mean > different things to each of us). Surely is means "

Re: How to simulate C style integer division?

2016-01-21 Thread Oscar Benjamin
On 21 January 2016 at 08:39, Shiyao Ma wrote: > > I wanna simulate C style integer division in Python3. > > So far what I've got is: > # a, b = 3, 4 > > import math > result = float(a) / b > if result > 0: > result = math.floor(result) > else: > r

Re: How to simulate C style integer division?

2016-01-21 Thread Jussi Piitulainen
Jussi Piitulainen writes: > Shiyao Ma writes: > >> I wanna simulate C style integer division in Python3. >> >> So far what I've got is: >> # a, b = 3, 4 >> >> import math >> result = float(a) / b >> if result > 0: >> result =

Re: How to simulate C style integer division?

2016-01-21 Thread Jussi Piitulainen
Paul Rubin writes: > Ben Finney writes: >> I'm not sure I know exactly what behaviour you want (“C style” may mean >> different things to each of us). > > I thought he meant trunc-division, so -5 / 2 = -2 and -5 % 2 = -1. > Python specifies floor division but C leaves it unspecified, I thought. I

Re: How to simulate C style integer division?

2016-01-21 Thread Paul Rubin
Ben Finney writes: > I'm not sure I know exactly what behaviour you want (“C style” may mean > different things to each of us). I thought he meant trunc-division, so -5 / 2 = -2 and -5 % 2 = -1. Python specifies floor division but C leaves it unspecified, I thought. -- https://mail.python.org/ma

Re: How to simulate C style integer division?

2016-01-21 Thread Ben Finney
Shiyao Ma writes: > I wanna simulate C style integer division in Python3. I'm not sure I know exactly what behaviour you want (“C style” may mean different things to each of us). I'll point out that Python's ‘//’ operator specifies floor division https://docs.pyth

Re: How to simulate C style integer division?

2016-01-21 Thread Jussi Piitulainen
Shiyao Ma writes: > I wanna simulate C style integer division in Python3. > > So far what I've got is: > # a, b = 3, 4 > > import math > result = float(a) / b > if result > 0: > result = math.floor(result) > else: > result = math.ceil(result) >

Re: How to simulate C style integer division?

2016-01-21 Thread Peter Heitzer
Shiyao Ma wrote: >Hi, >I wanna simulate C style integer division in Python3. >So far what I've got is: ># a, b = 3, 4 >import math >result = float(a) / b >if result > 0: > result = math.floor(result) >else: > result = math.ceil(result) >I found it&#

Re: How to simulate C style integer division?

2016-01-21 Thread Yann Kaiser
You can use the // operator, which should do what you want. On Thu, Jan 21, 2016, 09:40 Shiyao Ma wrote: > Hi, > > I wanna simulate C style integer division in Python3. > > So far what I've got is: > # a, b = 3, 4 > > import math > result = float(a) / b > if

How to simulate C style integer division?

2016-01-21 Thread Shiyao Ma
Hi, I wanna simulate C style integer division in Python3. So far what I've got is: # a, b = 3, 4 import math result = float(a) / b if result > 0: result = math.floor(result) else: result = math.ceil(result) I found it's too laborious. Any quick way? -- 吾輩は猫である。ホームーページはhttp

Re: python3 integer division debugging

2013-08-28 Thread Terry Reedy
On 8/28/2013 11:15 AM, Neal Becker wrote: The change in integer division seems to be the most insidious source of silent errors in porting code from python2 - since it changes the behaviour or valid code silently. In Python since 2.??, put 'from __future__ import integer_division'

Re: python3 integer division debugging

2013-08-28 Thread Neal Becker
Chris Angelico wrote: > On Thu, Aug 29, 2013 at 1:21 AM, Oscar Benjamin > wrote: >> On 28 August 2013 16:15, Neal Becker wrote: >>> The change in integer division seems to be the most insidious source of >>> silent errors in porting code from python2 - since i

Re: python3 integer division debugging

2013-08-28 Thread Chris Angelico
On Thu, Aug 29, 2013 at 1:21 AM, Oscar Benjamin wrote: > On 28 August 2013 16:15, Neal Becker wrote: >> The change in integer division seems to be the most insidious source of >> silent >> errors in porting code from python2 - since it changes the behaviour or valid >

Re: python3 integer division debugging

2013-08-28 Thread random832
On Wed, Aug 28, 2013, at 11:15, Neal Becker wrote: > The change in integer division seems to be the most insidious source of > silent > errors in porting code from python2 - since it changes the behaviour or > valid > code silently. > > I wish the interpreter had an instru

Re: python3 integer division debugging

2013-08-28 Thread Oscar Benjamin
On 28 August 2013 16:15, Neal Becker wrote: > The change in integer division seems to be the most insidious source of silent > errors in porting code from python2 - since it changes the behaviour or valid > code silently. > > I wish the interpreter had an instrumented mode to de

python3 integer division debugging

2013-08-28 Thread Neal Becker
The change in integer division seems to be the most insidious source of silent errors in porting code from python2 - since it changes the behaviour or valid code silently. I wish the interpreter had an instrumented mode to detect and report such problems. -- http://mail.python.org/mailman

Re: Integer Division

2009-06-19 Thread Terry Reedy
Anjanesh Lekshminarayanan wrote: a = 1 b = 25 a / b 0 float(a) / b 0.040001 from __future__ import division a = 1 b = 25 a / b 0.040001 In what simple way can I get just 0.04 ? Short answer: use 3.1: >>> 1//25 0 >>> 1/25 0.04 ;-) But you should really try to unde

Re: Integer Division

2009-06-19 Thread Grant Edwards
On 2009-06-19, Anjanesh Lekshminarayanan wrote: a = 1 b = 25 a / b > 0 float(a) / b > 0.040001 > from __future__ import division a = 1 b = 25 a / b > 0.040001 > > In what simple way can I get just 0.04 ? You can't. There _

Re: Integer Division

2009-06-19 Thread Dave Angel
Anjanesh Lekshminarayanan wrote: a = 1 b = 25 a / b 0 float(a) / b 0.040001 from __future__ import division a = 1 b = 25 a / b 0.040001 In what simple way can I get just 0.04 ? Your subject line says "Integer Div

Re: Integer Division

2009-06-19 Thread Piet van Oostrum
> Anjanesh Lekshminarayanan (AL) escribió: > a = 1 > b = 25 > a / b >AL> 0 > float(a) / b >AL> 0.040001 > > from __future__ import division > a = 1 > b = 25 > a / b >AL> 0.040001 > >AL> In what simple way can I get just 0.04

Re: Integer Division

2009-06-19 Thread Mark Dickinson
On Jun 19, 8:22 am, Anjanesh Lekshminarayanan wrote: > >>> a = 1 > >>> b = 25 > >>> a / b > 0 > >>> float(a) / b > > 0.040001 Python typically stores floats in binary, not decimal. The value 0.04 isn't exactly representable in binary, so the division float(1)/25 can't produce 0.04:

Re: Integer Division

2009-06-19 Thread Chris Rebert
On Fri, Jun 19, 2009 at 12:22 AM, Anjanesh Lekshminarayanan wrote: a = 1 b = 25 a / b > 0 float(a) / b > 0.040001 > from __future__ import division a = 1 b = 25 a / b > 0.040001 > > In what simple way can I get just 0.04 ? N

Integer Division

2009-06-19 Thread Anjanesh Lekshminarayanan
>>> a = 1 >>> b = 25 >>> a / b 0 >>> float(a) / b 0.040001 >>> >>> from __future__ import division >>> a = 1 >>> b = 25 >>> a / b 0.040001 >>> In what simple way can I get just 0.04 ? -- Anjanesh Lekshmnarayanan -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3.0 new integer division

2008-04-09 Thread Mark Dickinson
On Apr 9, 3:57 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > Naive question: why not just use a long + an exponent? > > e.g. 132560  -> (13256, 1) >      0.534   -> (534, -3) >      5.23e10 -> (523, 8) > It's a good question. The standard answer is that if the coefficient is a long then it's

Re: Python 3.0 new integer division

2008-04-09 Thread Arnaud Delobelle
On Apr 9, 8:35 pm, Mark Dickinson <[EMAIL PROTECTED]> wrote: > Strictly speaking, BCD doesn't come into it:  the coefficient of a > Decimal instance is stored simply as a string of digits.  This is > pretty wasteful in terms of space:  1 byte per decimal digit > instead of the 4 bits per digit that

Re: Python 3.0 new integer division

2008-04-09 Thread Mark Dickinson
On Apr 8, 6:01 pm, Jonathan Gardner <[EMAIL PROTECTED]> wrote: > On Apr 8, 2:25 pm, Grzegorz S³odkowicz <[EMAIL PROTECTED]> wrote: > > > > > Isn't Decimal a BCD implementation? > > Yep, you are right and I am > wrong.http://www.python.org/dev/peps/pep-0327/#why-not-rational Strictly speaking, BCD

Re: Python 3.0 new integer division

2008-04-08 Thread Jonathan Gardner
On Apr 8, 2:25 pm, Grzegorz Słodkowicz <[EMAIL PROTECTED]> wrote: > > Isn't Decimal a BCD implementation? Yep, you are right and I am wrong. http://www.python.org/dev/peps/pep-0327/#why-not-rational -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3.0 new integer division

2008-04-08 Thread Grzegorz Słodkowicz
> If you want precision with fractions, you should be using the Decimal > type, which uses a rational. A rational, if you recall from your math > classes, is one integer divided by another. > Isn't Decimal a BCD implementation? -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3.0 new integer division

2008-04-08 Thread Hutch
"Matimus" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Apr 8, 9:13 am, "Hutch" <[EMAIL PROTECTED]> wrote: >> We now have a float result when two integers are divided in the same >> mannor >> as 2.4 or 2.5. >> I can handle that and use the Floor division but a simple question.

Re: Python 3.0 new integer division

2008-04-08 Thread Matimus
On Apr 8, 9:13 am, "Hutch" <[EMAIL PROTECTED]> wrote: > We now have a float result when two integers are divided in the same mannor > as 2.4 or 2.5. > I can handle that and use the Floor division but a simple question. > > Why in the world would you round down the last presented digit to a 6 > inst

Re: Python 3.0 new integer division

2008-04-08 Thread Jonathan Gardner
On Apr 8, 9:13 am, "Hutch" <[EMAIL PROTECTED]> wrote: > We now have a float result when two integers are divided in the same mannor > as 2.4 or 2.5. > I can handle that and use the Floor division but a simple question. > > Why in the world would you round down the last presented digit to a 6 > inst

Python 3.0 new integer division

2008-04-08 Thread Hutch
We now have a float result when two integers are divided in the same mannor as 2.4 or 2.5. I can handle that and use the Floor division but a simple question. Why in the world would you round down the last presented digit to a 6 instead of just leaving it along as an 8. For some reason rounding

Re: Integer division

2007-06-07 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Dan Bishop wrote: > On Jun 7, 8:30 pm, Some Other Guy <[EMAIL PROTECTED]> wrote: >> Since this just involves doubling you can avoid multiplying altogether >> and just use this: >> >> def rounddiv(a,b): >> return int((a+a+b)/(b+b)) >> >> That's 3 integer adds and 1 integer

Re: Integer division

2007-06-07 Thread Terry Reedy
"Some Other Guy" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | [EMAIL PROTECTED] wrote: | | > Hello all, | > I have two integers and I want to divide one by another, and want to | > get an integer result which is the higher side whenever the result is | > a fraction. | > 3/2 =>

Re: Integer division

2007-06-07 Thread Dan Bishop
On Jun 7, 8:30 pm, Some Other Guy <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Hello all, > > I have two integers and I want to divide one by another, and want to > > get an integer result which is the higher side whenever the result is > > a fraction. > > 3/2 => 1 # Usual behavior >

Re: Integer division

2007-06-07 Thread Terry Reedy
"Sion Arrowsmith" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: | > 3/2 => 1 # Usual behavior | > some_func(3, 2) => 2 # Wanted | | def some_func(a, b): |return -(-a/b) | | And people complain about Python's behaviour regarding divi

Re: Integer division

2007-06-07 Thread Sion Arrowsmith
Hamish Moffatt <[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] wrote: > def div_ceil(a, b): >> ... if a%b: >> ... return ((a/b)+1) >> ... else: >> ... return (a/b) > >Yes, although it's not as short or as fast (probably as my version): > >def div_ceil(a, b): > return

Re: Integer division

2007-06-07 Thread Hamish Moffatt
[EMAIL PROTECTED] wrote: > On Jun 7, 2:15 pm, Hamish Moffatt <[EMAIL PROTECTED]> wrote: >> [EMAIL PROTECTED] wrote: >>> Hello all, >>> I have two integers and I want to divide one by another, and want to >>> get an integer result which is the higher side whenever the result is >>> a fraction. >>>

Re: Integer division

2007-06-07 Thread Sion Arrowsmith
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > 3/2 => 1 # Usual behavior > some_func(3, 2) => 2 # Wanted def some_func(a, b): return -(-a/b) And people complain about Python's behaviour regarding division of negative integers. -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/

Re: Integer division

2007-06-07 Thread [EMAIL PROTECTED]
On Jun 7, 2:15 pm, Hamish Moffatt <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Hello all, > > I have two integers and I want to divide one by another, and want to > > get an integer result which is the higher side whenever the result is > > a fraction. > > 3/2 => 1 # Usual behavior >

Re: Integer division

2007-06-07 Thread Hamish Moffatt
[EMAIL PROTECTED] wrote: > Hello all, > I have two integers and I want to divide one by another, and want to > get an integer result which is the higher side whenever the result is > a fraction. > 3/2 => 1 # Usual behavior > some_func(3, 2) => 2 # Wanted > > Any easier solution other than int(m

Integer division

2007-06-07 Thread [EMAIL PROTECTED]
Hello all, I have two integers and I want to divide one by another, and want to get an integer result which is the higher side whenever the result is a fraction. 3/2 => 1 # Usual behavior some_func(3, 2) => 2 # Wanted Any easier solution other than int(math.ceil(float(3)/2)) - Suresh -- http

Re: negative integer division

2005-02-10 Thread Mark Jackson
[EMAIL PROTECTED] (John Machin) writes: > [EMAIL PROTECTED] (Mark Jackson) wrote in message news:<[EMAIL PROTECTED]>... > > > > A: 42 > > > > Q: What multiple of 7 did I add to the critical expression in the Zeller > > algorithm so it would remain nonnegative for the next few centuries? >

Re: negative integer division

2005-02-10 Thread Mike Meyer
lers that use "ANSI C" as the target machine. By using C as a portable assembler instead of generating machine code, the number of supported platforms increases dramatically. >> Now, I'll agree with you if you want to argue that some machines do >> negative integer divisio

Re: negative integer division

2005-02-09 Thread John Machin
[EMAIL PROTECTED] (Mark Jackson) wrote in message news:<[EMAIL PROTECTED]>... > > A: 42 > > Q: What multiple of 7 did I add to the critical expression in the Zeller > algorithm so it would remain nonnegative for the next few centuries? What are you calling "the Zeller algorithm", and what

Re: negative integer division

2005-02-09 Thread Carl Banks
Jive Dadson wrote: > > Now, I'll agree with you if you want to argue that some machines do > > negative integer division in stupifyingly horrible ways. > > That's why I think it was a stupifyingly horrible decision. > Understandable, but in the end an s.h.d. nonethel

Re: negative integer division

2005-02-09 Thread Scott David Daniels
Jive Dadson wrote: I've forgotten what we are arguing about, but I'm sure I'm right. ^^^ QOTW --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: negative integer division

2005-02-09 Thread Peter Hansen
Grant Edwards wrote: This is pretty much completely off-topic now. :) No discussion of how lame other languages are is ever completely off-topic in comp.lang.python. After all, these discussions continue to remind us how lucky we all are to be able to program in Python, and that can only be a goo

Re: negative integer division

2005-02-09 Thread Grant Edwards
On 2005-02-09, Jive Dadson <[EMAIL PROTECTED]> wrote: > intentionally I disagree! -- Grant Edwards grante Yow! ... I don't like at FRANK SINATRA or his visi.comCHILDREN. --

Re: negative integer division

2005-02-09 Thread Grant Edwards
On 2005-02-09, Jive Dadson <[EMAIL PROTECTED]> wrote: [C] isn't - it's a portable assembler. >>> >>> I've heard that many times, but it makes no sense to me. >> >> I think the point is that C is a low-level, hardware twiddling >> language to be used by people writing things like kernel code

Re: negative integer division

2005-02-09 Thread Jive Dadson
intentionally -- http://mail.python.org/mailman/listinfo/python-list

Re: negative integer division

2005-02-09 Thread Jive Dadson
Grant Edwards wrote: > > On 2005-02-09, Jive Dadson <[EMAIL PROTECTED]> wrote: > > >> [C] isn't - it's a portable assembler. > > > > I've heard that many times, but it makes no sense to me. > > I think the point is that C is a low-level, hardware twiddling > language to be used by people writi

Re: negative integer division

2005-02-09 Thread Grant Edwards
ngs like kernel code -- something that was always done in assembler before C came along. >> Now, I'll agree with you if you want to argue that some >> machines do negative integer division in stupifyingly horrible >> ways. > > That's why I think it was a stupif

Re: negative integer division

2005-02-09 Thread Jive Dadson
st certainly not an assembler. > Now, I'll agree with you if you want to argue that some machines do > negative integer division in stupifyingly horrible ways. That's why I think it was a stupifyingly horrible decision. Understandable, but in the end an s.h.d. nonetheless. It wou

Re: negative integer division

2005-02-08 Thread Mike Meyer
oes. Now, I'll agree with you if you want to argue that some machines do negative integer division in stupifyingly horrible ways. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list

Re: negative integer division

2005-02-08 Thread Dan Bishop
Mark Jackson wrote: > Imbaud Pierre <[EMAIL PROTECTED]> writes: > > integer division and modulo gives different results in c and python, > > when negative numbers > > are involved. take gdb as a widely available c interpreter > > print -2 /3 > > 0 for c, -

Re: negative integer division

2005-02-08 Thread Jive Dadson
Python does it right. C is allowed to do it anyway it likes, which was a stupifyingly horrible decision, IMHO. Way back when, there was a language named Pascal. I lobbied the Pascal standards committee to define the modulus operator correctly, which they eventually did. To my astonishment, they

Re: negative integer division

2005-02-07 Thread Mark Jackson
Imbaud Pierre <[EMAIL PROTECTED]> writes: > integer division and modulo gives different results in c and python, > when negative numbers > are involved. take gdb as a widely available c interpreter > print -2 /3 > 0 for c, -1 for python. > more amazing, modulos of negat

Re: negative integer division

2005-02-07 Thread Scott David Daniels
Imbaud Pierre wrote: integer division and modulo gives different results in c and python, when negative numbers are involved. take gdb as a widely available c interpreter print -2 /3 0 for c, -1 for python. more amazing, modulos of negative number give negative values! (in c). from an algebraic

Re: negative integer division

2005-02-07 Thread Robert Kern
Imbaud Pierre wrote: integer division and modulo gives different results in c and python, when negative numbers are involved. take gdb as a widely available c interpreter print -2 /3 0 for c, -1 for python. more amazing, modulos of negative number give negative values! (in c). from an algebraic

Re: negative integer division

2005-02-07 Thread Skip Montanaro
Imbaud> integer division and modulo gives different results in c and Imbaud> python, when negative numbers are involved. http://www.python.org/doc/faq/programming.html#why-does-22-10-return-3 Skip -- http://mail.python.org/mailman/listinfo/python-list

negative integer division

2005-02-07 Thread Imbaud Pierre
integer division and modulo gives different results in c and python, when negative numbers are involved. take gdb as a widely available c interpreter print -2 /3 0 for c, -1 for python. more amazing, modulos of negative number give negative values! (in c). from an algebraic point of view, python