Comments (7)
open *it* up ... sorry, brain-o
Original comment by [email protected]
on 18 Feb 2008 at 4:34
from mpmath-2.
I think you've misread the benchmark page. mpmath is faster than Python's
decimal
module. It is *not* faster than Python's math module.
I don't understand the following:
Based on your benchmark data, I expected an improvement in performance just
for dropping it in (on equations that don't overflow with "math" and
therefore don't need the extra precision).
Why would you drop it in for equations that *don't* overflow with "math"?
If I've understood what you're trying to do, you should use the math module /
float
as far as possible and only switch to mpmath when standard floats overflow.
Could you please provide more details of what your code looks like?
I'm also curious about why it didn't overflow in Perl (were you using
BigFloat?).
Original comment by [email protected]
on 18 Feb 2008 at 7:19
from mpmath-2.
Thanks for a prompt reply.
Yes, I misread it. Thanks.
My plugin for the GIMP creates images from equations that the user provides.
Thus, I
don't know what functions are being used ahead of time. I have a few solutions
in
mind. Thanks.
I couldn't tell you why exp() didn't overflow in Perl when it did with "math" in
Python. I never looked into it because it always worked. In case you want to
look
into it further, I'm using ActivePerl 5.8.7 Build 813.
Original comment by [email protected]
on 18 Feb 2008 at 8:23
from mpmath-2.
Oh, and no, I did not use BigFloat...at least not explicitly.
Original comment by [email protected]
on 18 Feb 2008 at 8:25
from mpmath-2.
Here's a possible approach to your problem:
import math
import mpmath
def evalmath(expr):
try:
r = eval(expr, math.__dict__)
except OverflowError:
r = eval(expr, mpmath.__dict__)
try:
r = float(r)
except OverflowError:
pass
return r
>>> evalmath('sin(3)')
0.14112000805986721
>>>
>>> evalmath('exp(10000)')
mpf('8.8068182256629216e+4342')
>>>
>>> evalmath('exp(10000) / exp(10000)')
1.0
In other words, for highest speed float math is used by default. If overflow
occurs,
mpmath is used. The result is converted back to a float if possible to make
subsequent operations fast; an mpf is only returned if the final result is too
big.
Original comment by [email protected]
on 18 Feb 2008 at 9:01
from mpmath-2.
Thanks.
Original comment by [email protected]
on 18 Feb 2008 at 9:10
from mpmath-2.
I'm adding a description of this problem to the documentation.
Original comment by [email protected]
on 7 Mar 2008 at 8:40
- Changed state: Fixed
from mpmath-2.
Related Issues (20)
- Divide by Zero Error in ellippi HOT 2
- Determinant and inverse calculation is wrong
- Laguerre problem HOT 2
- mpmath and mathematica diverge at nearly 186 digits HOT 2
- Package installation issues on Ubuntu 12.04 HOT 1
- bisect fails if root is at midpoint of initial range HOT 1
- segmentation fault when calling the mpmath.mp.fraction(1,100).func(1000,None) HOT 2
- troubles using gmpy with mpmath HOT 6
- nsum convergence criteria HOT 2
- Changing limit of quadosc to -inf causes TypeError
- [deleted issue]
- save and load data - ValueError: invalid digits HOT 1
- left scalar multiplication of an interval matrix fails HOT 1
- This integral will not work HOT 4
- Typo in elliptic integral documentation HOT 1
- Equality testing for matrices assumes that entities tested are, in fact, matrices
- Proposal: mpmath.isfinite() HOT 1
- Bisection method fails with high precision
- findroot problem
- Trig and equality HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mpmath-2.