Connecting Tech Pros Worldwide Help | Site Map

gmpy

 
LinkBack Thread Tools Search this Thread
  #1  
Old September 29th, 2008, 05:02 PM
Newbie
 
Join Date: Aug 2008
Posts: 4
Default gmpy

python 2.5.2
ubuntu 8.04 LTS

(1) I find that python/gmpy is about 3 times slower than c++/gmp.
Is this the general experience, or am I doing something wrong?

(2) I am unable to understand the following error in conversion from float() to gmpy.mpf() or how to avoid it:

Expand|Select|Wrap|Line Numbers
  1. import gmpy
  2. gmpy.set_minprec(100)
  3. t= gmpy.mpf(7.99)
  4. print t
  5. print t/3
  6.  
prints:
7.990000000000000213162820728030055761337
2.663333333333333404387606909343351920446

I am new to both linux and python and would appreciate any expert help.

zakad
Reply
  #2  
Old October 3rd, 2008, 06:05 PM
Newbie
 
Join Date: Oct 2008
Posts: 1
Default

Hi,

Can you provide an example for performance question?

Python will have more overhead for each function call, so it will be slower when making multiple calls. The amount of slowdown should decrease as the size of the numbers increases.

Regarding your conversion question, you are converting the floating point approximation to 7.99 which is only accurate to about 18 decimal digits. If you convert the string "7.99" to an mpf, you'll get the value that I think you are expecting.

casevh
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.