Re: math module for Decimals

2009-01-06 Thread Mark Dickinson
On Mon, Jan 5, 2009 at 4:50 PM, alex goretoy aleksandr.gore...@gmail.com wrote: I get this when importing decimal: Python 2.7a0 (trunk:68339M, Jan 5 2009, 05:18:41) [GCC 3.4.6] on linux2 Type help, copyright, credits or license for more information. import decimal Traceback (most recent

Re: math module for Decimals

2009-01-06 Thread alex goretoy
Yes I ran strace python and imported math time(NULL) = 1231244692 futex(0x80575d8, FUTEX_WAKE, 1) = 0 stat64(math, 0xbfabef50) = -1 ENOENT (No such file or directory) open(math.so, O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)

Re: math module for Decimals

2009-01-06 Thread Fredrik Johansson
On Dec 28 2008, 4:55 pm, jerry.carl...@gmail.com wrote: - are you usingDecimalfor the base-10-ness or the   extra precisionDecimalprovides?  Or significant zeros?   Or compatibility with existingDecimalcode, or what? Oh boy, now I will finally prove myself illiterate... well, so be it.

Re: math module for Decimals

2009-01-06 Thread Mark Dickinson
On Jan 6, 3:23 pm, Fredrik Johansson fredrik.johans...@gmail.com wrote: FYI, mpmath (http://code.google.com/p/mpmath/) implements arbitrary- precision standard transcendental functions in pure Python. It is much faster than decimal, dmath, decimalfuncs and AJDecimalMathAdditions, and handles

Re: math module for Decimals

2009-01-06 Thread Fredrik Johansson
On Jan 6, 8:29 pm, Mark Dickinson dicki...@gmail.com wrote: Note that it's still subject to the same limitations as anything else for trig_function(really huge argument), of course: import mpmath mpmath.cos(mpmath.mpf('1e9')) [... still waiting for a result 30 minutes later ...]

Re: math module for Decimals

2009-01-05 Thread alex goretoy
Hmm. Maybe we shouldn't be using this syntax in from_float, if it's the only thing that prevents the trunk version of decimal.py from being used with Python 2.4. On the other hand, from_float isn't going to work until 2.7 anyway, since it uses a whole bunch of new stuff: as_integer_ratio

Re: math module for Decimals

2009-01-04 Thread Mark Dickinson
On Jan 4, 9:52 am, alex goretoy aleksandr.gore...@gmail.com wrote: Also, another reason why I'm posting to this thread. I noticed some error/typo in line 683 of decimal.py located on public svn repo. This is what is looks like.         sign = 0 if _math.copysign(1.0, f) == 1.0 else 1 This

Re: math module for Decimals

2009-01-04 Thread alex goretoy
No, I know there's a typo because python told me there is. If you have svn repo locally. then cd into Lib/ and run python decimal.py It will tell you line 683 has syntax error, please see below. haha python-svn # python Lib/decimal.py File Lib/decimal.py, line 683 sign = 0 if

Re: math module for Decimals

2009-01-04 Thread Mark Dickinson
On Jan 4, 10:38 am, alex goretoy aleksandr.gore...@gmail.com wrote: haha python-svn # python Lib/decimal.py   File Lib/decimal.py, line 683     sign = 0 if _math.copysign(1.0, f) == 1.0 else 1               ^ SyntaxError: invalid syntax Although, It may be only because I ran it through

Re: math module for Decimals

2009-01-04 Thread alex goretoy
I've been watching this thread for couple days now. I followed the bug report and all that stuff. It's very interesting to me how you guys talk about this stuff. I like it alot. I a new guy to python, just fyi. I'm one of my current projects I'm using Decimal as well and I think it be a huge pain

Re: math module for Decimals

2009-01-03 Thread Mark Dickinson
On Dec 31 2008, 11:02 pm, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Sun, 28 Dec 2008 06:38:32 -0800, Mark Dickinson wrote: On Dec 28, 7:28 am, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: Ah crap, I forgot that from_float() has been left out of the

Re: math module for Decimals

2009-01-03 Thread Mark Dickinson
On Jan 3, 9:27 pm, Mark Dickinson dicki...@gmail.com wrote: Decimal.from_float() implemented by Raymond Hettinger for Python 2.7 and Python 3.1, within 72 hours of Steven submitting the feature request.  If only all issues could be resolved this quickly. :-) Rats. I left out the crucial line

Re: math module for Decimals

2009-01-03 Thread Steven D'Aprano
On Sat, 03 Jan 2009 13:34:11 -0800, Mark Dickinson wrote: On Jan 3, 9:27 pm, Mark Dickinson dicki...@gmail.com wrote: Decimal.from_float() implemented by Raymond Hettinger for Python 2.7 and Python 3.1, within 72 hours of Steven submitting the feature request.  If only all issues could be

Re: math module for Decimals

2008-12-31 Thread Steven D'Aprano
On Sun, 28 Dec 2008 06:38:32 -0800, Mark Dickinson wrote: On Dec 28, 7:28 am, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: Ah crap, I forgot that from_float() has been left out of the decimal API. That's very annoying. Agreed. It's maybe even annoying enough that a feature

Re: math module for Decimals

2008-12-29 Thread Raymond L. Buvel
Since the interest is more in extended precision than in decimal representation, there is another module that may be of interest. http://calcrpnpy.sourceforge.net/clnum.html It interfaces to the Class Library for Numbers (CLN) library to provide both arbitrary precision floating point and

Re: math module for Decimals

2008-12-29 Thread Steve Holden
Raymond L. Buvel wrote: Since the interest is more in extended precision than in decimal representation, there is another module that may be of interest. http://calcrpnpy.sourceforge.net/clnum.html It interfaces to the Class Library for Numbers (CLN) library to provide both arbitrary

Re: math module for Decimals

2008-12-29 Thread rlbuvel
On Dec 29, 10:22 am, Steve Holden st...@holdenweb.com wrote: Raymond L. Buvel wrote: Since the interest is more in extended precision than in decimal representation, there is another module that may be of interest. http://calcrpnpy.sourceforge.net/clnum.html It interfaces to the Class

Re: math module for Decimals

2008-12-29 Thread Tino Wildenhain
jerry.carl...@gmail.com wrote: ... It's really just the goniometric functions that I am missing most at the moment, so maybe I can figure it out with help of what you said plus the already existing imperfect modules. Meantime maybe this discussion will caught Guido's eye... ;-) And btw I do

Re: math module for Decimals

2008-12-28 Thread Steven D'Aprano
On Sat, 27 Dec 2008 21:50:09 -0800, jerry.carl.mi wrote: Which math functions? ln, log10, exp, sqrt already exist as methods of Decimal instances. At the end of the Decimal docs there are a few examples, including computing sin and cos (but apparently they naïvely use a McLaurin series like

Re: math module for Decimals

2008-12-28 Thread jerry . carl . mi
Hi Steven... thanks for your kind and extensive reply. Lots of good food for thought. I know it's easy to complain about lack of functionality, but it really was not my intention. Python is very cool as it is and I still know too little about it to even suggest anything. I just thought maybe I was

Re: math module for Decimals

2008-12-28 Thread Mark Dickinson
On Dec 28, 12:02 am, jerry.carl...@gmail.com wrote: I have been looking for a Python module with math functions that would both eat and spit Decimals. The standard math module eats Decimals allright but spits floats. Yes: it just converts the input (whether float, int, Fraction or Decimal

Re: math module for Decimals

2008-12-28 Thread Mark Dickinson
On Dec 28, 7:28 am, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: Ah crap, I forgot that from_float() has been left out of the decimal API. That's very annoying. Agreed. It's maybe even annoying enough that a feature request at bugs.python.org might be honoured. (Hint, hint!)

Re: math module for Decimals

2008-12-28 Thread jerry . carl . mi
- are you using Decimal for the base-10-ness or the   extra precision Decimal provides?  Or significant zeros?   Or compatibility with existing Decimal code, or what? Oh boy, now I will finally prove myself illiterate... well, so be it. But i am after the extra precision: from math import *

Re: math module for Decimals

2008-12-28 Thread Mark Dickinson
On Dec 28, 3:55 pm, jerry.carl...@gmail.com wrote: But i am after the extra precision: from math import * (1+1e-16)-1 0.0 Sounds like you don't care too much about the base-10 part, so there may be other solutions out there. Have you tried: 1. mpmath? 2. sympy? 3. Sage? Any of these is

Re: math module for Decimals

2008-12-28 Thread jerry . carl . mi
1. mpmath? 2. sympy? 3. Sage? Haven't tried those, i guess i have some studying to do. x=Decimal.__mod__(x,Decimal('2')*pi()) Works fine for what i need, but i am sure it's not the right way to do it. I don't know of any better way to deal with large arguments. The main problem

Re: math module for Decimals

2008-12-28 Thread jerry . carl . mi
mpmath... wow... just did what i needed :-) Thanks, Mark! Hopefully i did not waste too much of your time... and perhaps this discussion will send other lost sheeps in the right direction. (Still, it would make sense to have the goniometric functions in decimal.) --

math module for Decimals

2008-12-27 Thread jerry . carl . mi
Hi, I have been looking for a Python module with math functions that would both eat and spit Decimals. The standard math module eats Decimals allright but spits floats... herefore exp(sin(Decimal())) produces exp () of a float :-( So far, i found: -AJDecimalMathAdditions (http://www.ajgs.com

Re: math module for Decimals

2008-12-27 Thread Gabriel Genellina
En Sat, 27 Dec 2008 22:02:51 -0200, jerry.carl...@gmail.com escribió: I have been looking for a Python module with math functions that would both eat and spit Decimals. The standard math module eats Decimals allright but spits floats... herefore exp(sin(Decimal())) produces exp () of a float

Re: math module for Decimals

2008-12-27 Thread jerry . carl . mi
Which math functions? ln, log10, exp, sqrt already exist as methods of   Decimal instances. At the end of the Decimal docs there are a few   examples, including computing sin and cos (but apparently they naïvely use   a McLaurin series like you noticed in other module). Hi Gabriel - thanks!

Re: math module for Decimals

2008-12-27 Thread Steven D'Aprano
On Sat, 27 Dec 2008 16:02:51 -0800, jerry.carl.mi wrote: Hi, I have been looking for a Python module with math functions that would both eat and spit Decimals. The standard math module eats Decimals allright but spits floats... herefore exp(sin(Decimal())) produces exp () of a float

Re: math module for Decimals

2008-12-27 Thread Steven D'Aprano
On Sun, 28 Dec 2008 06:58:18 +, Steven D'Aprano wrote: def make_decimal(f, precision=16): # choose how many decimal places you want to keep return Decimal.from_float(f, precision) Ah crap, I forgot that from_float() has been left out of the decimal API. That's very annoying.