Skip to content

Divide by Zero Error in ellippi #268

Description

@fredrik-johansson
What steps will reproduce the problem? 1. ellippi(1,1)
2. ellippi(1,0)
3. ellippi(1,>pi/2,0 or 1) What is the expected output? What do you see instead? Divide by Zero Error and nan What version of the product are you using? On what operating system? Python 3.2.3, mpmath 0.17, win7pro 64bit Please provide any additional information below. I have not used either Python or mpmath before, so my code fix may not be correct or optimal. The code seems to work and is at the end of the elliptic.py module.

        if complete:
            #if m == 0: return ctx.pi/(2*ctx.sqrt(1-n)) #removed by JCB, div/0 error
            if m == 0:                                  #added by JCB
                if n == 1: return ctx.inf               #added by JCB 
                return ctx.pi/(2*ctx.sqrt(1-n))         #added by JCB
            if n == 0: return ctx.ellipk(m)
            if ctx.isinf(n) or ctx.isinf(m): return ctx.zero
        else:
            if z == 0: return z
            if ctx.isinf(n): return ctx.zero
            if ctx.isinf(m): return ctx.zero
        if ctx.isinf(n) or ctx.isinf(z) or ctx.isinf(m):
            raise ValueError
    if complete:
        #if m == 1: return -ctx.inf/ctx.sign(n-1)   #removed by JCB, div/0 error
        if m == 1:                                  #added by JCB
            if n > 1: return -ctx.inf               #added by JCB
            return ctx.inf                          #added by JCB                
        away = False
    else:
        x = z.real
        ctx.prec += max(0, ctx.mag(x))
        pi = +ctx.pi
        away = abs(x) > pi/2
    if away:
        d = ctx.nint(x/pi)
        z = z-pi*d
        P = 2*d*ctx.ellippi(n,m)
        if ctx.isinf(P): return P   #added by JCB, return "(+/-)inf" instead of "nan"
    else:

Original issue for #268: http://code.google.com/p/mpmath/issues/detail?id=228
Original author: https://code.google.com/u/108619376443136823458/

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions