Code Monkey home page Code Monkey logo

Comments (7)

GoogleCodeExporter avatar GoogleCodeExporter commented on May 19, 2024
open *it* up ... sorry, brain-o

Original comment by [email protected] on 18 Feb 2008 at 4:34

from mpmath-2.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 19, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 19, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 19, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 19, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 19, 2024
Thanks.

Original comment by [email protected] on 18 Feb 2008 at 9:10

from mpmath-2.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 19, 2024
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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.