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 /
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
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.
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
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
way-to-round-towards-zero-in-integer-division
--
https://mail.python.org/mailman/listinfo/python-list
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?
>
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
>
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
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
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
Perhaps the "secret" is *not* do integer division with negative numbers?
--
https://mail.python.org/mailman/listinfo/python-list
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
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
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
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
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
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
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
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'
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.
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
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
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
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:
>>>
>>>
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
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 =
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
>
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 "
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
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 =
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
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
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
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)
>
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
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
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
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'
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
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
>
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
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
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
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
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 _
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
> 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
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:
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
>>> 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
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
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
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
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
> 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
"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.
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
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
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
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
"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 =>
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
>
"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
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
[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.
>>>
[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/
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
>
[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
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
[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?
>
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
[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
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
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
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
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.
--
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
intentionally
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
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, -
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
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
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
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
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
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
90 matches
Mail list logo