Ticket #7828: trac_7828-reviewer.patch

File trac_7828-reviewer.patch, 1.6 KB (added by cremona, 12 years ago)

Apply after previous

  • sage/functions/generalized.py

    # HG changeset patch
    # User John Cremona <john.cremona@gmail.com>
    # Date 1275037384 -3600
    # Node ID d0b0b35d4c0e8bf6812a554f188406d80ea91ac1
    # Parent  a2daa22c5b2286d8cb90f8143214d06a60169240
    #7828 reviewer patch (support x.sgn() and make return type Integer)
    
    diff -r a2daa22c5b22 -r d0b0b35d4c0e sage/functions/generalized.py
    a b  
    5252##############################################################################
    5353
    5454from sage.symbolic.function import BuiltinFunction
    55 from sage.rings.complex_interval_field import ComplexIntervalField
     55from sage.rings.all import ComplexIntervalField, ZZ
    5656
    5757class FunctionDiracDelta(BuiltinFunction):
    5858    r"""
     
    473473        """
    474474        if hasattr(x,'sign'): # First check if x has a sign method
    475475            return x.sign()
     476        if hasattr(x,'sgn'): # or a sgn method
     477            return x.sgn()
    476478        try:
    477479            approx_x = ComplexIntervalField()(x)
    478480            if bool(approx_x.imag() == 0):      # x is real
    479481                if bool(approx_x.real() == 0):  # x is zero
    480                     return 0
     482                    return ZZ(0)
    481483                # Now we have a non-zero real
    482484                if bool((approx_x**(0.5)).imag() == 0): # Check: x > 0
    483                     return 1
     485                    return ZZ(1)
    484486                else:
    485                     return -1
     487                    return ZZ(-1)
    486488        except:                     # x is symbolic
    487489            pass   
    488490        return None