# 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 ############################################################################## from sage.symbolic.function import BuiltinFunction from sage.rings.complex_interval_field import ComplexIntervalField from sage.rings.all import ComplexIntervalField, ZZ class FunctionDiracDelta(BuiltinFunction): r""" """ if hasattr(x,'sign'): # First check if x has a sign method return x.sign() if hasattr(x,'sgn'): # or a sgn method return x.sgn() try: approx_x = ComplexIntervalField()(x) if bool(approx_x.imag() == 0):      # x is real if bool(approx_x.real() == 0):  # x is zero return 0 return ZZ(0) # Now we have a non-zero real if bool((approx_x**(0.5)).imag() == 0): # Check: x > 0 return 1 return ZZ(1) else: return -1 return ZZ(-1) except:                     # x is symbolic pass return None