Re: Bug in floating-point addition: is anyone else seeing this?

2008-05-22 Thread Mark Dickinson
On May 22, 6:57 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > > > I wonder how you would accomplish that, given that there is no fix. > > http://hal.archives-ouvertes.fr/hal-00128124 > > Diez For anyone still following the discussion, I highly recommend the above mentioned paper; I found it

Re: Why is math.pi slightly wrong?

2008-05-22 Thread Mark Dickinson
On May 22, 12:32 pm, "Dutton, Sam" <[EMAIL PROTECTED]> wrote: > I've noticed that the value of math.pi -- just entering it at the interactive > prompt -- is returned as 3.1415926535897931, whereas (as every pi-obsessive > knows) the value is 3.1415926535897932... (Note the 2 at the end.) > There

Re: binary representation of an integer

2008-06-24 Thread Mark Dickinson
On Jun 24, 9:03 am, eliben <[EMAIL PROTECTED]> wrote: > What would be the quickest way to do this ? I think that for dec2bin > conversion, using hex() and then looping with a hex->bin lookup table > would be probably much faster than the general baseconvert from the > recipe. I suspect you're righ

Re: complex numbers should respect the "I" representation

2008-06-28 Thread Mark Dickinson
On Jun 28, 1:48 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > hi > > I think complex numbers should respect the "i" or "I" representation, > instead of "j". > No reason being cute and using a different character instead of the > traditional representation? At least have the decency of suppor

Re: re.search much slower then grep on some regular expressions

2008-07-05 Thread Mark Dickinson
On Jul 5, 1:54 pm, Carl Banks <[EMAIL PROTECTED]> wrote: > I don't think you've illustrated that at all.  What you've illustrated > is that one implementation of regexp optimizes something that another > doesn't.  It might be due to differences in complexity; it might not. > (Maybe there's somethin

Re: numeric emulation and __pos__

2008-07-08 Thread Mark Dickinson
On Jul 8, 12:12 am, Ethan Furman <[EMAIL PROTECTED]> wrote: > 1) Any reason to support the less common operators? >         i.e. <<, >>, &, ^, | No reason to support any of these for a nonintegral nonbinary type, as far as I can see. > 2) What, exactly, does .__pos__() do?  An example would help,

Re: new itertools functions in Python 2.6

2008-07-16 Thread Mark Dickinson
On Jul 16, 7:20 am, Mensanator <[EMAIL PROTECTED]> wrote: > > > ##  Combinations with replacement > > > ##  - > > > ##  aaa aab aac aad aae abb abc abd abe acc acd ace > > > ##  add ade aee bbb bbc bbd bbe bcc bcd bce bdd bde > > > ##  bee ccc ccd cce cdd cde cee ddd dde

Re: round function error???

2008-07-18 Thread Mark Dickinson
On Jul 18, 10:17 pm, Anthony <[EMAIL PROTECTED]> wrote: > Isn't this a mistake??? Which 'this'? That is, what were you expecting? If you're objecting to the fact that the second result produces 3499.34999 instead of 3499.35, then no, that's not a mistake; see http://www.python.org/doc/

Re: round function error???

2008-07-18 Thread Mark Dickinson
On Jul 18, 11:15 pm, Terry Reedy <[EMAIL PROTECTED]> wrote: > No, round() return binary floats that, in general, cannot represent > decimal floats exactly.  Formatted printing gives what you expect. >  >>> '%8.2f' % x > ' 3499.35' Sure. But it's still true that the second printed value (printed a

Re: round function error???

2008-07-20 Thread Mark Dickinson
On Jul 19, 12:20 am, John Machin <[EMAIL PROTECTED]> wrote: > On Jul 19, 8:05 am, Mark Dickinson <[EMAIL PROTECTED]> wrote: > > for more information.  But I'm guessing that you're > > questioning the fact that a value that's apparently > > *le

Re: python 64bits on macosx.5 /leopard

2008-08-14 Thread Mark Dickinson
On Aug 14, 11:25 am, "Mathieu Prevot" <[EMAIL PROTECTED]> wrote: > in order to run django on apache, I need mod_python in apache, and it > runs in 64 on leopard, so I need to run python in 64 bits. > I tryed ./configure --enable-framework OPT="-arch x86_64" but make fails: There was a thread on th

Re: Best way to check if string is an integer?

2008-04-05 Thread Mark Dickinson
On Apr 5, 6:19 pm, [EMAIL PROTECTED] wrote: > which is the best way to check if a string is an number or a char? > could the 2nd example be very expensive timewise if i have to check a > lot of strings? You might be interested in str.isdigit: >>> print str.isdigit.__doc__ S.isdigit() -> bool Ret

Re: A funnily inconsistent behavior of int and float

2008-04-06 Thread Mark Dickinson
On Apr 6, 1:29 pm, Lie <[EMAIL PROTECTED]> wrote: > I've noticed some oddly inconsistent behavior with int and float: > > Python 2.5.1 (r251:54863, Mar  7 2008, 03:39:23) > [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2>>> > int('-          345') > > -345 > > works, but > > >

Re: A funnily inconsistent behavior of int and float

2008-04-07 Thread Mark Dickinson
On Apr 7, 6:43 am, "Colin J. Williams" <[EMAIL PROTECTED]> wrote: > This is good but the documentation for > 3.0 is missing the syntax documentation > from 2.5 Is http://docs.python.org/dev/3.0/reference/lexical_analysis.html#integer-literals the documentation that you're looking for? But it se

Re: A funnily inconsistent behavior of int and float

2008-04-07 Thread Mark Dickinson
On Apr 7, 3:15 pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > > My suggestions: > 1. Change signature to: int([number | string[, radix]). > This makes it clear that radix can only follow a string without having to > say so in the text. > > 2. Replace text with: > Convert a number or string to an in

Re: A funnily inconsistent behavior of int and float

2008-04-07 Thread Mark Dickinson
On Apr 7, 3:53 pm, Mark Dickinson <[EMAIL PROTECTED]> wrote: > The only base 0 versus base 10 difference I could find was the > following: > > >>> int('033', 0) > > Traceback (most recent call last): > File "", line 1, in > ValueError:

Re: A funnily inconsistent behavior of int and float

2008-04-07 Thread Mark Dickinson
On Apr 7, 4:59 pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > "Mark Dickinson" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > > Thank you for the corrections. Here is my revised proposal: > > int([number | string[, radix]) &g

Re: what's the reasonale of loghelper() in mathmodule.c

2008-04-09 Thread Mark Dickinson
On Apr 9, 4:38 am, rockins <[EMAIL PROTECTED]> wrote: > I cannot understand it well, can anyone explain me why and how > loghelper() can compute any base logarithm? Or could anyone give me > some reference(such as, books or papers)? loghelper is there so that log(n) can be computed for any positiv

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-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: Rounding a number to nearest even

2008-04-11 Thread Mark Dickinson
On Apr 11, 10:29 am, hdante <[EMAIL PROTECTED]> wrote: > Strangely, a "faster" version is: > > def fast_round(x): > if x % 1 != 0.5: return round(x) > return 2.0*round(x/2.0) You should be a little bit careful with the test x%1 == 0.5 if x might be negative: >>> x = -0.5 + 2**-54 >>> x

Re: Rounding a number to nearest even

2008-04-11 Thread Mark Dickinson
On Apr 11, 2:33 pm, Lie <[EMAIL PROTECTED]> wrote: > In this table, we consider that a number is rounded down when the > number is equal to truncated value (the number without fractional > part), while round up is equal to truncated value + 1 or truncated > value -1 if value is negative (Actually t

Re: Rounding a number to nearest even

2008-04-13 Thread Mark Dickinson
On Apr 13, 4:18 am, Lie <[EMAIL PROTECTED]> wrote: [...] > it and there is nothing else in it, but in the second number range > (barely above 1 to 2) the number 1.0 is not included while the number > 2.0 is contained in it, clearly not a clean separation of numbers in > the form of y.x where y is p

Re: def power, problem when raising power to decimals

2008-04-16 Thread Mark Dickinson
On Apr 16, 4:19 pm, [EMAIL PROTECTED] wrote: > how do i solve power(5,1.3)? > [...] > > also i found a link which states 0^0 isnt 1 even though every > calculator ive tried says it is. > it doesnt say what it is but i presume 0 then. > but it seems the dude is wrong and it is 1? >>> 5**1.3 8.10328

Re: def power, problem when raising power to decimals

2008-04-17 Thread Mark Dickinson
On Apr 16, 11:03 pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > | decimal.InvalidOperation: 0 ** 0 > > I would think of this as a bug unless the standard Decimal follows demands > this. It does. From http://www2.hursley.ibm.com/decimal/daops.html#refpower : "If both operands are zero, or if the

Re: Comparing float and decimal

2008-09-24 Thread Mark Dickinson
On Sep 23, 7:31 pm, Terry Reedy <[EMAIL PROTECTED]> wrote: > Decimal is something of an anomaly in Python because it was written to > exactly follow an external standard, with no concessions to what would > be sensible for Python.  It is possible that that standard mandates that > Decimals not comp

Re: Comparing float and decimal

2008-09-25 Thread Mark Dickinson
On Sep 24, 6:18 pm, Terry Reedy <[EMAIL PROTECTED]> wrote: > If there is not now, there could be in the future, and the decimal > authors are committed to follow the standard wherever it goes. > Therefore, the safe course, to avoid possible future deprecations due to > doing too much, is to only do

Re: Comparing float and decimal

2008-09-25 Thread Mark Dickinson
On Sep 25, 8:55 am, Tim Roberts <[EMAIL PROTECTED]> wrote: > Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > >0.1 actually is > > >In [98]: '%.50f' % 0.1 > >Out[98]: '0.1555111512312578270211815834045410' > >? > > Actually, it's not.  Your C run-time library is generating rand

Re: Comparing float and decimal

2008-09-25 Thread Mark Dickinson
On Sep 23, 1:58 pm, Robert Lehmann <[EMAIL PROTECTED]> wrote: > I don't see why transitivity should apply to Python objects in general. Hmmm. Lack of transitivity does produce some, um, interesting results when playing with sets and dicts. Here are sets s and t such that the unions s | t and t |

Re: Comparing float and decimal

2008-09-30 Thread Mark Dickinson
On Sep 30, 9:21 am, Terry Reedy <[EMAIL PROTECTED]> wrote: > If no one beats me to it, I will probably file a bug report or two, but > I am still thinking about what to say and to suggest. I can't see many good options here. Some possibilities: (0) Do nothing besides documenting the problem some

Re: Comparing float and decimal

2008-10-01 Thread Mark Dickinson
On Sep 30, 8:07 pm, Terry Reedy <[EMAIL PROTECTED]> wrote: > Documenting the problem properly would mean changing the set > documentation to change at least the definitions of union (|), issubset > (<=), issuperset (>=), and symmetric_difference (^) from their current > math set based definitions t

Re: need clarification on -0

2009-11-28 Thread Mark Dickinson
On Nov 28, 8:39 pm, Tim Roberts wrote: > moijes12 wrote: > > >I know the value -0 is quite meaningless and makes little sense.But I > >was just fiddling.I am unable to figure out the below result > > -0 and True > >0 --> (Why is this 0 and not say True or False) > -0 and false >

Re: need clarification on -0

2009-11-28 Thread Mark Dickinson
On Nov 28, 11:14 pm, Mark Dickinson wrote: > While that's true, I think the implementation of Python is > such that the Python objects -0 and 0 should always be > indistinguishable even on machines where the underlying > architecture represents integers using ones' compleme

Re: Moving from Python 2 to Python 3: A 4 page "cheat sheet"

2009-12-01 Thread Mark Dickinson
On Dec 1, 2:03 pm, Mark Summerfield wrote: > I've produced a 4 page document that provides a very concise summary > of Python 2<->3 differences plus the most commonly used new Python 3 > features. Very nice indeed! My only quibble is with the statement on the first page that the 'String % operat

Re: Moving from Python 2 to Python 3: A 4 page "cheat sheet"

2009-12-02 Thread Mark Dickinson
On Dec 2, 8:01 am, Mark Summerfield wrote: > On 1 Dec, 17:50, Mark Dickinson wrote: > > My only quibble is with the statement on the first page that > > the 'String % operator is deprecated'.  I'm not sure that's > > true, for all values of '

Re: Moving from Python 2 to Python 3: A 4 page "cheat sheet"

2009-12-02 Thread Mark Dickinson
On Dec 2, 4:41 pm, "John Posner" wrote: >   Goal: place integer 456 flush-right in a field of width 8 > >    Py2: "%%%dd" % 8 % 456 >    Py3: "{0:{1}d}".format(456, 8) > > With str.format(), you don't need to nest one formatting operation within   > another. A little less mind-bending, and every l

Re: Float precision and float equality

2009-12-05 Thread Mark Dickinson
On Dec 5, 3:37 pm, Anton81 wrote: > I'd like to do calculations with floats and at some point equality of > two number will be checked. > What is the best way to make sure that equality of floats will be > detected, where I assume that mismatches beyond a certain point are > due to truncation erro

Re: Float precision and float equality

2009-12-05 Thread Mark Dickinson
On Dec 5, 8:25 pm, Raymond Hettinger wrote: > On Dec 5, 7:37 am, Anton81 wrote: > > > I'd like to do calculations with floats and at some point equality of > > two number will be checked. > > What is the best way to make sure that equality of floats will be > > detected, where I assume that misma

Re: Float precision and float equality

2009-12-07 Thread Mark Dickinson
On Dec 6, 7:34 pm, Anton81 wrote: > I do some linear algebra and whenever the prefactor of a vector turns > out to be zero, I want to remove it. Hmm. Comparing against zero is something of a special case. So you'd almost certainly be doing an 'if abs(x) < tol: ...' check, but the question is wh

Re: Float precision and float equality

2009-12-07 Thread Mark Dickinson
On Dec 7, 12:16 am, David Cournapeau wrote: > If you can depend on IEEE 754 semantics, one relatively robust method > is to use the number of representable floats between two numbers. The > main advantage compared to the proposed methods is that it somewhat > automatically takes into account the a

Re: which pi formula is given in the decimal module documentation?

2009-12-11 Thread Mark Dickinson
On Dec 11, 8:16 am, Anh Hai Trinh wrote: > I'm just curious which formula for pi is given here: docs.python.org/library/decimal.html#recipes>? > > def pi(): >     """Compute Pi to the current precision. > >     >>> print pi() >     3.141592653589793238462643383 > >     """ >     getcontext().prec

Re: which pi formula is given in the decimal module documentation?

2009-12-11 Thread Mark Dickinson
On Dec 11, 10:30 am, Mark Dickinson wrote: > > It looks like an infinite series with term `t`, where`n` = (2k-1)^2 > > and `d` = d = 4k(4k+2) for k = 1... Does it have a name? > > Interesting.  So the general term here is > 3 * (2k choose k) / (16**k * (2*k+1)),  k >= 0. &

Re: which pi formula is given in the decimal module documentation?

2009-12-11 Thread Mark Dickinson
On Dec 11, 8:16 am, Anh Hai Trinh wrote: > I'm just curious which formula for pi is given here: docs.python.org/library/decimal.html#recipes>? > > def pi(): >     """Compute Pi to the current precision. > >     >>> print pi() >     3.141592653589793238462643383 > >     """ >     getcontext().prec

Re: Apple Mac OS X 10.6 support & compatability with Python 3 ?

2009-12-16 Thread Mark Dickinson
On Dec 16, 5:41 pm, pdlem...@earthlink.net wrote: > I've been given a MAC AIR laptop with OS X 10.6 "Snow Leopard". > On my desktop I dual boot with XP - Ubuntu and have Python on both. > Unfortunately all my Python programs are written on Windows XP and > I heavily rely on WConio for console I/O.

Re: force non-exponential representation for Decimal?

2009-12-23 Thread Mark Dickinson
On Dec 23, 10:03 am, jh...@gmx.de wrote: > (cc-ing the list) Thanks. Looks like I'm still having trouble distinguishing between 'Reply' and 'Reply to author'. I'll have to work on my reading abilities over the break... > > > Is there a convenient way to force a decimal.Decimal representation to

Re: the need for 64 bits

2009-12-28 Thread Mark Dickinson
On Dec 28, 6:50 am, Mensanator wrote: > But with a 64-bit processor, that limitation no longer stops me. > > i: 11   bits: 10,460,353,205   decimals:  3,148,880,080 > i: 12   bits: 94,143,178,829   decimals: 28,339,920,715 > > Wow! 94 billion bits! 28 billion decimal digits! > > Of course, once o

Re: C Module's '1.#INF' changes to 'inf' at Python

2010-01-09 Thread Mark Dickinson
On Jan 8, 3:36 pm, Robert Kern wrote: > On 2010-01-08 07:48 AM, CELEN Erman wrote: > > My problem is that I’ve noticed a strange behavior in Python while > > handling FPEs on Windows after switching compilers (msvc8 to msvc9) and > > I am trying to find out how Python handles INF values to figure

Re: How to get many places of pi from Machin's Equation?

2010-01-09 Thread Mark Dickinson
On Jan 9, 11:31 am, "Richard D. Moores" wrote: > Is there a way in Python 3.1 to calculate pi to greater accuracy using > Machin's Equation? Even to an arbitrary number of places? There's no arbitrary-precision version of atan included with Python. You could write your own (e.g., based on argumen

Re: How to get many places of pi from Machin's Equation?

2010-01-09 Thread Mark Dickinson
On Jan 9, 11:31 am, "Richard D. Moores" wrote: > Machin's Equation is > > 4 arctan (1/5) - arctan(1/239) = pi/4 > [...] > > Is there a way in Python 3.1 to calculate pi to greater accuracy using > Machin's Equation? Even to an arbitrary number of places? Here's some crude code (no error bounds,

Re: Best way to convert sequence of bytes to long integer

2010-01-20 Thread Mark Dickinson
On Jan 20, 7:36 am, Steven D'Aprano wrote: > I have a byte string (Python 2.x string), e.g.: > > s = "g%$f yg\n1\05" > assert len(s) == 10 > > I wish to convert it to a long integer, treating it as base-256. Not that it helps you right now, but provided someone finds the time, there should be an

Re: Best way to convert sequence of bytes to long integer

2010-01-20 Thread Mark Dickinson
On Jan 20, 7:36 am, Steven D'Aprano wrote: > I have a byte string (Python 2.x string), e.g.: > > s = "g%$f yg\n1\05" > assert len(s) == 10 > > I wish to convert it to a long integer, treating it as base-256. By the way, are you willing to divulge what you're using this functionality for? When tr

Re: decimal threading cost?

2010-01-22 Thread Mark Dickinson
On Jan 22, 11:11 am, Robin Becker wrote: > Does using the decimal module incur a penalty because it imports threading or > do > I have to actually start a thread? There is at least one threading-related performance penalty that doesn't involve the user actually starting a thread: any arithmetic

Re: Symbols as parameters?

2010-01-22 Thread Mark Dickinson
On Jan 21, 10:57 pm, Martin Drautzburg wrote: > Here is a complete expample using a decorator, still a bit noisy > > def move(aDirection): >     print "moving " + aDirection > > #Here comes the decorator > def scope(aDict): >     def save(locals): > [...] Have you considered making 'scope' a cont

Re: enumerated while loop

2010-01-23 Thread Mark Dickinson
On Jan 23, 2:44 pm, Roald de Vries wrote: > I assume a function like 'naturals' already exists, or a similar   > construction for the same purpose. But what is it called? itertools.count() -- Mark -- http://mail.python.org/mailman/listinfo/python-list

Re: Need help with a program

2010-01-28 Thread Mark Dickinson
On Jan 28, 3:07 pm, evilweasel wrote: > Hi folks, > > I am a newbie to python, and I would be grateful if someone could > point out the mistake in my program. > for j in range(0, b): >     if lister[j] == 0: At a guess, this line should be: if lister[j] == '0': ... -- Mark -- ht

Re: Got undefined symbol: _PyUnicodeUCS2_AsDefaultEncodedString on OpenSuSE 11.1

2009-09-25 Thread Mark Dickinson
On Sep 25, 7:05 pm, Alejandro Valdez wrote: > Hello I sent this e-mail to the python-help list but I'm not sure if > that list is active... so I post it again here: > > I'm trying to build Python 2.6.2 from the sources downloaded from the > python official site on OpenSuSE 11.1 (32 bit). After ins

Re: Got undefined symbol: _PyUnicodeUCS2_AsDefaultEncodedString on OpenSuSE 11.1

2009-09-25 Thread Mark Dickinson
On Sep 25, 7:56 pm, Mark Dickinson wrote: > On Sep 25, 7:05 pm, Alejandro Valdez > wrote: > > Hello I sent this e-mail to the python-help list but I'm not sure if > > that list is active... so I post it again here: > > > I'm trying to build Python 2.6.2

Re: Got undefined symbol: _PyUnicodeUCS2_AsDefaultEncodedString on OpenSuSE 11.1

2009-09-27 Thread Mark Dickinson
On Sep 25, 10:13 pm, Alejandro Valdez wrote: > The compiler issued some warnings, two of them (related to Unicode) > called my attention: > > In file included from Python/formatter_unicode.c:13: > Python/../Objects/stringlib/formatter.h: In function > ‘unknown_presentation_type’: > Python/../

Re: variable scope

2009-09-28 Thread Mark Dickinson
On Sep 28, 9:37 am, Bruno Desthuilliers wrote: > Joel Juvenal Rivera Rivera a écrit : > > > > > Yeah i forgot the self an try the code then i see > > an error that it was not defines _uno__a so that's > > where i define the global and see that behavior. > > (snip) > >> Joel Juvenal Rivera Rivera w

Re: variable scope

2009-09-29 Thread Mark Dickinson
On Sep 29, 11:11 am, Bruno Desthuilliers wrote: > Mark Dickinson a écrit : > > On Sep 28, 9:37 am, Bruno Desthuilliers > 42.desthuilli...@websiteburo.invalid> wrote: > >> Looks like a bug to me. I Think you should fill a ticket... > > > I don't think it&

Re: int rich comparisons

2009-10-02 Thread Mark Dickinson
On Oct 2, 3:52 pm, George Sakkis wrote: > I stumbled upon the following strangeness (python 2.6.2): > > >>> getattr(int, '__gt__') > > > > >>> getattr(5, '__gt__') > > Traceback (most recent call last):n >   File "", line 1, in > AttributeError: 'int' object has no attribute '__gt__' > > Is this

Re: Fast decimal arithmetic module released

2009-10-02 Thread Mark Dickinson
On Oct 2, 8:53 pm, Stefan Krah wrote: > Hi, > > today I have released the following packages for fast arbitrary precision > decimal arithmetic: > [...] Nice! I'd been wondering how you'd been finding all those decimal.py bugs. Now I know. :) -- Mark -- http://mail.python.org/mailman/listinfo

Re: Python-3.2 (SVN) bug [was syntax question]

2009-10-12 Thread Mark Dickinson
On Oct 12, 7:55 am, Helmut Jarausch wrote: > I wrote > I'm trying to build the recent Python-3.2a (SVN). > It fails in > Lib/tokenize.py  (line 87) > > 85  def group(*choices): return '(' + '|'.join(choices) + ')' > 86  def any(*choices): return group(*choices) + '*' > 87  def maybe(*choices): ret

Re: Python-3.2 (SVN) bug [was syntax question]

2009-10-12 Thread Mark Dickinson
On Oct 12, 7:55 am, Helmut Jarausch wrote: > I wrote > I'm trying to build the recent Python-3.2a (SVN). > It fails in > Lib/tokenize.py  (line 87) [...] > with: TypeError: group() argument after ** must be a mapping, not tuple I believe I've found the source of this problem: the --with-tsc conf

Re: for loop: range() result has too many items

2009-10-14 Thread Mark Dickinson
On Oct 13, 10:39 pm, Steven D'Aprano wrote: > On Tue, 13 Oct 2009 16:17:58 -0500, Peng Yu wrote: > > Hi, > > > The following code does not run because range() does not accept a big > > number. > > Incorrect. > > >>> range(sys.maxint+2, sys.maxint+5) > > [2147483649L, 2147483650L, 2147483651L] For

Re: for loop: range() result has too many items

2009-10-15 Thread Mark Dickinson
On Oct 15, 8:39 pm, David C. Ullrich wrote: > >For what it's worth, there *is* a Python oddity lurking > >under the surface here, at least for 64-bit.  Here's > >Python 2.6 on a 64-bit machine: > > Is that a 64-bit Python as well? Yes. Mark -- http://mail.python.org/mailman/listinfo/python-list

Re: struct curiosity

2009-10-16 Thread Mark Dickinson
On Oct 15, 7:07 pm, pjcoup wrote: > I was fooling around with python's struct lib, looking on how we'd > unpack some data.  I was a little confused by its behavior: > Python 2.5.2 (r252:60911, Jul 22 2009, 15:33:10) > [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 > Type "help", "copyright", "credi

Re: restriction on sum: intentional bug?

2009-10-17 Thread Mark Dickinson
On Oct 17, 3:27 pm, a...@pythoncraft.com (Aahz) wrote: > In article <0062f568$0$26941$c3e8...@news.astraweb.com>, > Steven D'Aprano   wrote: > > (For the record, summing lists is O(N**2), and unlike strings, there's no > > optimization in CPython to avoid the slow behaviour.) > > Are you sure? The

Re: restriction on sum: intentional bug?

2009-10-17 Thread Mark Dickinson
On Oct 17, 9:49 pm, a...@pythoncraft.com (Aahz) wrote: > Ahhh, I vaguely remember there being some discussion of this when sum() > was introduced -- I think that using InPlaceAdd would have caused bad > behavior when the initial list was referred to by multiple names. Ah yes. Good point. With my

Re: restriction on sum: intentional bug?

2009-10-17 Thread Mark Dickinson
On Oct 17, 9:49 pm, a...@pythoncraft.com (Aahz) wrote: > Ahhh, I vaguely remember there being some discussion of this when sum() > was introduced -- I think that using InPlaceAdd would have caused bad > behavior when the initial list was referred to by multiple names. Thanks for the pointer: I've

Re: unittest wart/bug for assertNotEqual

2009-10-20 Thread Mark Dickinson
On Oct 20, 6:20 pm, Zac Burns wrote: > Using the assertNotEqual method of UnitTest (synonym for failIfEqual) > only checks if first == second, but does not include not (first != > second) It looks as though this is fixed in Python 2.7 (and also in 3.1): http://svn.python.org/view?view=rev&revisi

Re: Struct on on x86_64 mac os x

2009-10-21 Thread Mark Dickinson
On Oct 20, 10:51 pm, Tommy Grav wrote: > I have created a binary file that saves this struct from some C code: > >    struct recOneData { >           char label[3][84]; >           char constName[400][6]; >         double timeData[3]; >       long int numConst; >         double AU; >         doubl

Re: Struct on on x86_64 mac os x

2009-10-21 Thread Mark Dickinson
On Oct 21, 9:18 am, Mark Dickinson wrote: > On Oct 20, 10:51 pm, Tommy Grav wrote: > > >      def read_header(cls): > >          hdrData = "84s"*3 > >          constNData = "6s"*400 > > I'm confused:  why is this not "400s"*6

Re: repr(complex) in Py3.1

2009-10-24 Thread Mark Dickinson
On Oct 24, 3:26 pm, Stefan Behnel wrote: > Hi, > > in Python 3.1.1, I get this: > >   Python 3.1.1 (r311:74480, Oct 22 2009, 19:34:26) >   [GCC 4.3.2] on linux2 >   Type "help", "copyright", "credits" or "license" for more information. >   >>> 2j >   2j >   >>> -2j >   -2j >   >>> -0-2j >   -2j >

Re: Strange behavior related to value / reference

2009-10-28 Thread Mark Dickinson
On Oct 28, 8:24 am, Lambda wrote: > Thank you! > Following is my final code: Looks good, but are you sure about that word 'final'? ;-) > > def matrix_power(m, n): >   """ >   Raise 2x2 matrix m to nth power. >   """ >   if n == 0: return [[1, 0], [0, 1]] > >   x = matrix_power(m, n / 2) I sugg

Re: unable to compile Python 2.6.4 on AIX using gcc

2009-11-04 Thread Mark Dickinson
On Nov 3, 10:40 pm, chuck wrote: > Hello -- I am trying to compile Python 2.6.4 on a Power 5 PC with AIX > 5.3.  Here are the settings: > > export OBJECT_MODE=64 > export AR="ar -X64" > export MAKE=/usr/bin/gmake > export CC="gcc" > export CFLAGS="-maix64 -O2 -g -mcpu=power5" > export LDFLAGS="-L/

Re: Python C API and references

2009-11-12 Thread Mark Dickinson
On Nov 12, 9:23 am, "lallous" wrote: > Hello, > > Everytime I use PyObject_SetAttrString(obj, attr_name, py_val) and I don't > need the reference to py_val I should decrement the reference after this > call? Not necessarily: it depends where py_val came from. I find the 'ownership' model descri

Re: Slicing history?

2009-11-15 Thread Mark Dickinson
On Nov 15, 6:50 pm, a...@pythoncraft.com (Aahz) wrote: > Anyone remember or know why Python slices function like half-open > intervals?  I find it incredibly convenient myself, but an acquaintance > familiar with other programming languages thinks it's bizarre and I'm > wondering how it happened.

Re: Language mavens: Is there a programming with "if then else ENDIF" syntax?

2009-11-17 Thread Mark Dickinson
On Nov 16, 4:54 pm, Steve Ferg wrote: > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > >     if then >         do stuff >     elif then >         do stuff >     else >         do stuff >     endif > > Note that you do not need block delimi

Re: Sorting: too different times. Why?

2009-11-22 Thread Mark Dickinson
On Nov 22, 9:21 am, n00m wrote: > Any comment: > > class Vector: >     def __init__(self, x, y): >         self.x = x >         self.y = y >     def __cmp__(self, v): >         if self.x < v.x and self.y > v.y: >             return -1 >         return 0 > > def v_cmp(v1, v2): >     if v1.x < v2.x

Re: unencountered error in FFT python

2010-01-31 Thread Mark Dickinson
On Jan 30, 8:20 pm, uche wrote: > Another issue: >     x[a], x[b] = x[(a)] + W[(n % N)] * x[(b)], x[(a)] - W[(n % N)] * x > [(b)] > TypeError: can't multiply sequence by non-int of type 'complex' With your original code, the elements of array2 are strings, and here Python is refusing to multiply

Re: unencountered error in FFT python

2010-01-31 Thread Mark Dickinson
On Jan 31, 10:02 am, Mark Dickinson wrote: > Python is refusing to multiply the string x[a] by the complex number W > [n % N]. Whoops, that should have been "x[b]", not "x[a]". Why is it that a post-submission proofread turns up errors so much more often than

Re: How to guard against bugs like this one?

2010-02-02 Thread Mark Dickinson
On Feb 2, 3:28 am, Steven D'Aprano wrote: > > There is no module numbers in the standard library, at least not in 2.5. It's new in 2.6 (and 3.0, I think; it's there in 3.1, anyway). It provides abstract base classes for numeric types; see the fractions module source for some of the ways it can

Re: Common area of circles

2010-02-04 Thread Mark Dickinson
On 2/4/2010 7:05 AM, Shashwat Anand wrote: > I want to calculate areas. > like for two circles (0, 0) and (0, 1) : the output is '1.228370' > > similarly my aim is to take 'n' co-ordinates, all of radius '1' and > calculate the area common to all. > The best I got was monte-carlo methods which is i

Re: Last M digits of expression A^N

2010-02-05 Thread Mark Dickinson
On Feb 5, 8:14 pm, mukesh tiwari wrote: > Hello everyone. I am kind of new to python so pardon me if i sound > stupid. > I have to find out the last M digits of expression.One thing i can do > is (A**N)%M but my  A and N are too large (10^100) and M is less than > 10^5. The other approach   was  r

Re: Last M digits of expression A^N

2010-02-06 Thread Mark Dickinson
On Feb 5, 8:14 pm, mukesh tiwari wrote: > I have to find out the last M digits of expression.One thing i can do > is (A**N)%M but my  A and N are too large (10^100) and M is less than > 10^5. The other approach   was  repeated squaring and taking mod of > expression. Is there any other way to do t

Re: max / min / smallest float value on Python 2.5

2010-02-07 Thread Mark Dickinson
On Feb 7, 12:52 am, duncan smith wrote: > import platform > if platform.architecture()[0].startswith('64'): >      TINY = 2.2250738585072014e-308 > else: >      TINY = 1.1754943508222875e-38 As Christian said, whether you're using 32-bit or 64-bit shouldn't make a difference here. Just use the f

Re: max / min / smallest float value on Python 2.5

2010-02-07 Thread Mark Dickinson
On Feb 7, 8:45 pm, duncan smith wrote: [...] > interested, but the following pseudo-python gives the idea.  For an [...] >              try: >                  yield rand() < exp(dF / temp) Practically speaking, the condition rand() < exp(dF / temp) is never going to be satisfied if dF / temp <

Re: Ternary plus

2010-02-10 Thread Mark Dickinson
On Feb 9, 6:47 pm, Martin Drautzburg wrote: > BTW I am not really trying to add three objects, I wanted a third object > which controls the way the addition is done. Sort of like "/" and "//" > which are two different ways of doing division. That seems like a reasonable use case for a third param

Re: Ternary plus

2010-02-10 Thread Mark Dickinson
On Feb 10, 8:31 am, Mark Dickinson wrote: > And here's how it's used in the decimal.Context module: Aargh! decimal.Context *class*, not module. And it occurs to me that it would have been cleaner to have Decimal.__add__ call Context.add rather than the other way around. Then De

Re: Bizarre arithmetic results

2010-02-11 Thread Mark Dickinson
On Feb 11, 12:44 am, Terrence Cole wrote: > Can someone explain to me what python is doing here? > >>> -0.1 ** 0.1 > -0.7943282347242815 Here you're computing -(0.1 ** 0.1). The exponentiation operator binds more strongly than the negation operator. > >>> a = -0.1; b = 0.1 > >>> a ** b > (0.75

Re: Bizarre arithmetic results

2010-02-11 Thread Mark Dickinson
On Feb 11, 1:38 pm, Duncan Booth wrote: > Tim Chase wrote: > > But perhaps Py3 changes evaluation, returning an complex number. > > Yes, the change is documented > athttp://docs.python.org/3.1/reference/expressions.html#the-power-operator > > If it is in any of the "What's new in Python x.xx" do

Re: Python Optimization

2010-02-14 Thread Mark Dickinson
On Feb 14, 4:53 pm, mukesh tiwari wrote: > Hello everyone. I am new to python and previously i did programming in > c/c++.Could some one please help me to improve the run time for this > python program as i don't have idea how to optimized this code. > [...] How much of a speedup do you need? Ar

Re: Python Optimization

2010-02-14 Thread Mark Dickinson
On Feb 14, 6:03 pm, a...@pythoncraft.com (Aahz) wrote: > In article > <363498c7-3575-4f1e-ad53-d9cd10c8d...@q16g2000yqq.googlegroups.com>, > Mark Dickinson   wrote: > > >(2) Obvious things: use range rather than xrange in your loops.   > > Um, what?  You meant the r

Re: Python Optimization

2010-02-14 Thread Mark Dickinson
On Feb 14, 4:53 pm, mukesh tiwari wrote: > Hello everyone. I am new to python and previously i did programming in > c/c++.Could some one please help me to improve the run time for this > python program as i don't have idea how to optimized this code.This > code also seems to be more unpythonic so

Re: Precision issue in python

2010-02-20 Thread Mark Dickinson
On Feb 20, 11:17 am, mukesh tiwari wrote: > Hello everyone. I think it is  related to the precision with double > arithmetic so i posted here.I am trying with this problem > (https://www.spoj.pl/problems/CALCULAT) and the problem say that "Note : for > all test cases whose N>=100, its K<=15." I k

Re: Precision issue in python

2010-02-20 Thread Mark Dickinson
On Feb 20, 3:37 pm, mukesh tiwari wrote: > I don't know if is possible to import this decimal module but kindly > tell me.Also a bit about log implementation The decimal module is part of the standard library; I don't know what the rules are for SPOJ, but you're already importing the math module

Re: Precision issue in python

2010-02-20 Thread Mark Dickinson
On Sat, Feb 20, 2010 at 2:42 PM, Shashwat Anand wrote: > A quick solution I came out with, no stirling numbers and had tried to avoid > large integer multiplication as much as possible. > > import math > > for i in range(int(raw_input())): >     n, k, l = [int(i) for i in raw_input().split()] >   

Re: formatting a number as percentage

2010-02-21 Thread Mark Dickinson
On Feb 21, 5:53 pm, vsoler wrote: > I'm trying to print .7 as 70% > I've tried: > > print format(.7,'%%') > .7.format('%%') > > but neither works. I don't know what the syntax is... Assuming that you're using Python 2.6 (or Python 3.x): >>> format(.7, '%') '70.00%' >>> format(.7, '.2%') '70.

Re: Bizarre arithmetic results

2010-02-23 Thread Mark Dickinson
On Feb 23, 8:11 am, Steven D'Aprano wrote: > Making spaces significant in that fashion is mind-bogglingly awful. Let's > look at a language that does this: > > [st...@sylar ~]$ cat ws-example.rb > def a(x=4) >     x+2 > end > > b = 1 > print (a + b), (a+b), (a+ b), (a +b), "\n" > > [st...@sylar ~]

<    1   2   3   4   5   >