By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,665 Members | 1,229 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,665 IT Pros & Developers. It's quick & easy.

about presicion

P: n/a
Ali
I was wondering if it was posible to get very good presicion. I mean
like to the to the 100 th or more decimal place. if so how?
Jul 18 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
al**********@hotmail.com (Ali) wrote in message news:<8f**************************@posting.google. com>...
I was wondering if it was posible to get very good presicion. I mean
like to the to the 100 th or more decimal place. if so how?


You can have infinite, or at least arbitrary precision, if you do all
calculations on rational numbers. Doing this will probably be very
slow compared to calculations on floats, ints, or longs, however,
especially if implemented in pure Python.

A compromise would be to use a fixed-point representation. If you
needed 100 decimal digits after the decimal point, and say, 10 before
the decimal point, you could accomplish that (and actually a teeny bit
more) using a 368-bit fixed-point representation. This could possibly
be fast in Python, depending on the implementation.

It all depends what your requirements are.
Jul 18 '05 #2

P: n/a
Mensanator <me********@aol.compost> wrote:
Subject: Re: about presicion
From: Peter Hansen pe***@engcorp.com
Date: 8/28/04 10:31 PM Central Daylight Time
Message-id: <JN********************@powergate.ca>

Ali wrote:
The decimal module comes with python 2.4? I have 2.3, :(, what do I do?
The obvious answer is, well, obvious. The real question is
what's stopping you from upgrading?


I just tried it and found out it's not compatible with gmpy.


By "it" do you mean Decimal, or Python 2.4 alpha 2? I think gmpy should
build happily with the latter, and interoperate sensibly with Decimal
anyway -- as gmpy's author I'd be quite happy to fix gmpy if it's broken
in either respect.
Of course, I wouldn't need gmpy to get big floats, but I
would then lose all the math functions like linear congruence
and modular inverse that my programs depend on.

So I, for one, will have to wait for the rest of the world to
catch up to 2.4.


2.4 is not currently recommended for production work (that's why it's in
Alpha -- very good for an alpha, but it's still not a final release).
But such support modules as gmpy need to get moving to support 2.4 in
order to be ready for it well before final release...
Alex
Jul 18 '05 #3

P: n/a
Ali <al**********@hotmail.com> wrote:
So the decimal module is in 2.4 but not 2.3? Also I am not geting the
2.4 version because it seems that it is still in alpha.


You _SHOULD_ get the 2.4 alpha, and try it out -- that's why alphas get
released, after all! How's the final release going to be perfect unless
people DO get and try the alphas?!

But you shouldn't yet use 2.4 for production work (stuff you ship to
customers, etc).

The Decimal module is in the standard library in 2.4, but Decimal itself
can support 2.3 just fine -- just download and install it.
Alex
Jul 18 '05 #4

P: n/a
Ali
al*****@yahoo.com (Alex Martelli) wrote in message news:<1gjc18t.1hj0z071lwprfjN%al*****@yahoo.com>.. .
Ali <al**********@hotmail.com> wrote:
So the decimal module is in 2.4 but not 2.3? Also I am not geting the
2.4 version because it seems that it is still in alpha.


You _SHOULD_ get the 2.4 alpha, and try it out -- that's why alphas get
released, after all! How's the final release going to be perfect unless
people DO get and try the alphas?!

But you shouldn't yet use 2.4 for production work (stuff you ship to
customers, etc).

The Decimal module is in the standard library in 2.4, but Decimal itself
can support 2.3 just fine -- just download and install it.
Alex


ok but where can i download deciaml? waht about gmpy? which is better?
Jul 18 '05 #5

P: n/a
Ali <al**********@hotmail.com> wrote:
...
ok but where can i download deciaml? waht about gmpy? which is better?


Decimal (for 2.3): file decimal.py from:
http://cvs.sourceforge.net/viewcvs.p.../dist/src/Lib/

With 2.4 it will come as part of the standard library.

gmpy: http://gmpy.sourceforge.net.\/
"Which is better" for _WHAT_ task? If you need decimal arithmetic,
obviously Decimal, since gmpy doesn't support it -- gmpy uses binary
throughout. If you need huge-precision binary floats,
unbounded-precision rational numbers, very fast operations such as
factorials and binomial coefficients on unbounded-precision integers,
then obviously gmpy, since Decimal doesn't support any of these --
Decimal does its job, which is decimal arithmetic, period.

I cannot imagine offhand any task for which I would be in doubt between
using Decimal and using gmpy -- sure, they both deal with numbers, but
there's basically no overlap between their functionality.
Alex
Jul 18 '05 #6

P: n/a
me********@aol.com <me********@aol.com> wrote:
...
I just tried it and found out it's not compatible with gmpy.


By "it" do you mean Decimal, or Python 2.4 alpha 2?


By "it", I meant gmpy 1.0 and Python 2.4. Trying to import the
module says it can't use the Python23.dll.


_Any_ binary extension Python module compiled for Python 2.3 cannot even
load (on Windows) with Python 2.4 -- this has always been true on
Windows between any two releases of Python and will presumably continue
to be so for the foreseeable future.

This doesn't mean that Python 2.4 "is not compatible with gmpy" or
viceversa: it just means you obviously need to use a gmpy binary (pyd
file) compiled for the version of Python you're using. Just as it would
be the case for any other binary extension module whatsoever.

Unfortunately, compiling any binary extension module on Windows for
Python 2.4 requires Microsoft's very latest C++ compiler -- I do not own
a copy, nor do I have any PC normally running Windows XP, which is
required to run that compiler. Until Pyhon 2.3, I made do with a
Windows 98 session running under win4lin on one of my Linux machines,
and good old Microsoft Visual C++ 6 -- but such limited resources are
not sufficient any longer to compile Python binary extension modules for
Python 2.4. Since in terms of income-making (as well as leisure;-) I
work by now only on MacOSX, Linux, and OpenBSD machines, I am not going
to buy a PC loaded with Microsoft software just to be able to donate
precompiled Python binary extension modules to Windows users.

I think gmpy should
build happily with the latter,


I'm using the pre-built Windows binary distribution. I wouldn't
know how to re-build it. I assume that when Python 2.4 is final,
I newer compatible version of gmpy will become available.


Not by magic -- I hope somebody out there owns all the needed Microsoft
software and is interested in compiling gmpy for Windows under Python
2.4 and making it available, but it won't be me.

and interoperate sensibly with Decimal
anyway -- as gmpy's author I'd be quite happy to fix gmpy if it's

broken
in either respect.


Were you aware that there is apparently a memory leak in the
gmpy.divm() function? Calling it several million time caused my
computer to run out of virtual memeory. Luckily, I was able to
work around it using the gmpy.invert() which didn't consume any
memory regardless of how many times it was called.


No, I was not aware of that -- I'll look into it, thanks.
Alex
Jul 18 '05 #7

P: n/a
Anthony Baxter <an***********@gmail.com> wrote:
Another approach is to find someone with the appropriate toolchain
(VS7.1) and get them to do:

% python setup.py install
% python setup.py bdist_wininst

and then make the windows installer for the gmpy module available.
Sounds good -- are you volunteering?-)

My understanding is that building 2.4 modules with either mingw or the
freely available MS compiler is still a non-trivial exercise - but
there's enough people interested in this that I suspect it will be
resolved soon enough.


Thanks for the info! And let's indeed hope things get better... if
mingw sufficed I could use it on my old trusty Win98-on-Win4Lin-
on-Linux setup, for example (gmpy does need speed, so maybe it's best to
build it with the best optimizing compiler available, but other modules
may not be quite as speed-critical as that).
Alex
Jul 18 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.