Ticket #8896: 8896-rebased.patch

File 8896-rebased.patch, 12.8 KB (added by robertwb, 8 years ago)

Folded and rebased on 4.7. Apply only this patch.

  • doc/en/numerical_sage/numpy.rst

    # HG changeset patch
    # User Robert Bradshaw <robertwb@math.washington.edu>
    # Date 1273962973 25200
    # Node ID d6c95f7280a90339854a44dfaf9af84ec60f83f7
    # Parent  43d7e32917c314a8f3a1aa565a9de5ffbc5298a3
    #8896 - High precision zero parsed incorrectly, better precision handling for real/complex literals.
    
    diff -r 43d7e32917c3 -r d6c95f7280a9 doc/en/numerical_sage/numpy.rst
    a b  
    3939    array([1099511627776, 12157665459056928801, 1208925819614629174706176], dtype=object)
    4040    sage: a=2.0000000000000000001                               
    4141    sage: a.prec() # higher precision than hardware floating point numbers
    42     67
     42    70
    4343    sage: numpy.array([a,2*a,3*a])
    44     array([2.000000000000000000, 4.000000000000000000, 6.000000000000000000], dtype=object)
     44    array([2.0000000000000000001, 4.0000000000000000002, 6.0000000000000000003], dtype=object)
    4545
    4646
    4747The ``dtype`` attribute of an array tells you the type of the array.
  • doc/en/reference/coercion.rst

    diff -r 43d7e32917c3 -r d6c95f7280a9 doc/en/reference/coercion.rst
    a b  
    5151    True
    5252    sage: ZZ
    5353    Integer Ring
    54     sage: parent(1.50000000000000000000000000000000000)
     54    sage: parent(1.5000000000000000000000000000000000)
    5555    Real Field with 120 bits of precision
    5656    sage: parent(x)
    5757    Symbolic Ring
  • sage/combinat/combinat.py

    diff -r 43d7e32917c3 -r d6c95f7280a9 sage/combinat/combinat.py
    a b  
    19481948        sage: hurwitz_zeta(11/10,1/2,6)
    19491949        12.1041000000000
    19501950        sage: hurwitz_zeta(11/10,1/2,50)
    1951         12.10381349568375510570907741296668061903364861809
     1951        12.103813495683755105709077412966680619033648618089
    19521952   
    19531953    REFERENCES:
    19541954
  • sage/functions/special.py

    diff -r 43d7e32917c3 -r d6c95f7280a9 sage/functions/special.py
    a b  
    10341034            sage: b.n(53)
    10351035            0.0145459669825056
    10361036            sage: Bessel(6, typ='I', algorithm="maxima")(pi)
    1037             0.0294619840059568
     1037            0.029461984005956805
    10381038            sage: Bessel(6, typ='Y', algorithm="maxima")(pi)
    10391039            -4.33932818939038
    10401040
  • sage/functions/transcendental.py

    diff -r 43d7e32917c3 -r d6c95f7280a9 sage/functions/transcendental.py
    a b  
    520520        sage: dickman_rho(10)
    521521        2.77017183772596e-11
    522522        sage: dickman_rho(10.00000000000000000000000000000000000000)
    523         2.77017183772595898875812120063434232634e-11
     523        2.770171837725958988758121200634342326343e-11
    524524        sage: plot(log(dickman_rho(x)), (x, 0, 15))
    525525   
    526526    AUTHORS:
  • sage/graphs/generic_graph.py

    diff -r 43d7e32917c3 -r d6c95f7280a9 sage/graphs/generic_graph.py
    a b  
    1285612856            sage: Graph()._layout_bounding_box( {0: [3,5], 1: [2,7], 2: [-4,2] } )
    1285712857            [-4, 3, 2, 7]
    1285812858            sage: Graph()._layout_bounding_box( {0: [3,5], 1: [3.00000000001,4.999999999999999] } )
    12859             [2, 4.00000000001000, 4.00000000000000, 6]
     12859            [2, 4.00000000001000, 3.999999999999999, 6]
    1286012860        """
    1286112861        xs = [pos[v][0] for v in pos]
    1286212862        ys = [pos[v][1] for v in pos]
  • sage/rings/complex_interval.pyx

    diff -r 43d7e32917c3 -r d6c95f7280a9 sage/rings/complex_interval.pyx
    a b  
    12121212        sage: ComplexIntervalFieldElement(1,2.000000000000000000000)
    12131213        1 + 2*I
    12141214        sage: ComplexIntervalFieldElement(1.234567890123456789012345, 5.4321098654321987654321)
    1215         1.234567890123456789012350? + 5.432109865432198765432000?*I
     1215        1.2345678901234567890123450? + 5.4321098654321987654321000?*I
    12161216    """
    12171217    if s_imag is None:
    12181218        s_imag = 0
  • sage/rings/complex_number.pyx

    diff -r 43d7e32917c3 -r d6c95f7280a9 sage/rings/complex_number.pyx
    a b  
    3030
    3131from complex_double cimport ComplexDoubleElement
    3232from real_mpfr cimport RealNumber
     33from real_mpfr import create_RealNumber
    3334
    3435import complex_field
    3536import sage.misc.misc
     
    18771878       
    18781879            sage: b = ComplexNumber(float(exp(42)),0)
    18791880            sage: b.log()
    1880             41.99999999999971
     1881            42.0000000000000
    18811882
    18821883        ::
    18831884       
     
    21752176
    21762177def create_ComplexNumber(s_real, s_imag=None, int pad=0, min_prec=53):
    21772178    r"""
     2179    This function is defined as ComplexNumber in the global namespace and
     2180    is used by the preparser to create complex literals.
     2181   
    21782182    Return the complex number defined by the strings s_real and
    21792183    s_imag as an element of ``ComplexField(prec=n)``,
    21802184    where n potentially has slightly more (controlled by pad) bits than
     
    21962200   
    21972201    EXAMPLES::
    21982202   
     2203        sage: 1.5j
     2204        1.50000000000000*I
     2205        sage: 1.50000000000000000000000000000000000000000000000000j
     2206        1.50000000000000000000000000000000000000000000000000*I
    21992207        sage: ComplexNumber('2.3')
    22002208        2.30000000000000
    22012209        sage: ComplexNumber('2.3','1.1')
     
    22052213        sage: ComplexNumber(10,10)
    22062214        10.0000000000000 + 10.0000000000000*I
    22072215        sage: ComplexNumber(1.000000000000000000000000000,2)
    2208         1.00000000000000000000000000 + 2.00000000000000000000000000*I
     2216        1.000000000000000000000000000 + 2.000000000000000000000000000*I
    22092217        sage: ComplexNumber(1,2.000000000000000000000)
    2210         1.00000000000000000000 + 2.00000000000000000000*I
     2218        1.000000000000000000000 + 2.000000000000000000000*I
    22112219   
    22122220    ::
    22132221   
    22142222        sage: sage.rings.complex_number.create_ComplexNumber(s_real=2,s_imag=1)
    22152223        2.00000000000000 + 1.00000000000000*I
    22162224    """
     2225    # Most common case (preparsed literal).
     2226    if s_real is 0:
     2227        if isinstance(s_imag, str) and len(s_imag) < 15 and pad == 0 and min_prec == 53:
     2228            return ComplexNumber(complex_field.ComplexField(53), 0, s_imag)
     2229        else:
     2230            imag = create_RealNumber(s_imag, 10, pad, "RNDN", min_prec)
     2231            return ComplexNumber(imag.parent().complex_field(), 0, imag)
     2232   
    22172233    if s_imag is None:
    2218         s_imag = 0
    2219        
    2220     if not isinstance(s_real, str):
    2221         s_real = str(s_real).strip()
    2222     if not isinstance(s_imag, str):
    2223         s_imag = str(s_imag).strip()
    2224     #if base == 10:
    2225     bits = max(int(3.32192*len(s_real)),int(3.32192*len(s_imag)))
    2226     #else:
    2227     #    bits = max(int(math.log(base,2)*len(s_imag)),int(math.log(base,2)*len(s_imag)))
    2228        
    2229     C = complex_field.ComplexField(prec=max(bits+pad, min_prec))
    2230        
    2231     return ComplexNumber(C, s_real, s_imag)
     2234        s_imag = 0.
     2235   
     2236    real = create_RealNumber(s_real, 10, pad, "RNDN", min_prec)
     2237    imag = create_RealNumber(s_imag, 10, pad, "RNDN", min_prec)
     2238
     2239    C = complex_field.ComplexField(prec=max(real.prec(), imag.prec(), min_prec))
     2240    return ComplexNumber(C, real, imag)
    22322241
    22332242
    22342243cdef class RRtoCC(Map):
  • sage/rings/rational_field.py

    diff -r 43d7e32917c3 -r d6c95f7280a9 sage/rings/rational_field.py
    a b  
    121121        sage: QQ(23.2, 2)
    122122        6530219459687219/281474976710656
    123123        sage: 6530219459687219.0/281474976710656
    124         23.20000000000000
     124        23.199999999999999
    125125        sage: a = 23.2; a
    126126        23.2000000000000
    127127        sage: QQ(a, 10)
  • sage/rings/real_mpfr.pyx

    diff -r 43d7e32917c3 -r d6c95f7280a9 sage/rings/real_mpfr.pyx
    a b  
    48714871
    48724872def create_RealNumber(s, int base=10, int pad=0, rnd="RNDN", int min_prec=53):
    48734873    r"""
    4874     Return the real number defined by the string s as an element of
     4874    This function is defined as RealNumber in the global namespace and
     4875    is used by the preparser to create real literals.
     4876   
     4877    Returns the real number defined by the string s as an element of
    48754878    ``RealField(prec=n)``, where n potentially has slightly
    4876     more (controlled by pad) bits than given by s.
     4879    more (controlled by pad) bits than given by the number of
     4880    significant figures of s.
    48774881   
    48784882    INPUT:
    48794883   
    48804884   
    4881     -  ``s`` - a string that defines a real number (or
     4885    -  `s` -- a string that defines a real number (or
    48824886       something whose string representation defines a number)
    48834887   
    4884     -  ``base`` - an integer between 2 and 36
     4888    -  `base` -- an integer (default 10) between 2 and 36
    48854889   
    4886     -  ``pad`` - an integer = 0.
     4890    -  `pad` -- an integer (default 0)
    48874891   
    4888     -  ``rnd`` - rounding mode: RNDN, RNDZ, RNDU, RNDD
     4892    -  `rnd` -- rounding mode (defa: RNDN, RNDZ, RNDU, RNDD
    48894893   
    4890     -  ``min_prec`` - number will have at least this many
    4891        bits of precision, no matter what.
     4894    -  `min_prec` -- (default 53) minimum bits of precision, no matter what.
    48924895   
    48934896   
    48944897    EXAMPLES::
     
    48984901        sage: RealNumber(10)
    48994902        10.0000000000000
    49004903        sage: RealNumber('1.0000000000000000000000000000000000')
    4901         1.000000000000000000000000000000000
     4904        1.0000000000000000000000000000000000
    49024905        sage: RealField(200)(1.2)
    49034906        1.2000000000000000000000000000000000000000000000000000000000
    49044907        sage: (1.2).parent() is RR
    49054908        True
    49064909       
    4907     TESTS::
     4910   
     4911    Leading zeros don't contribute to the precision::
    49084912   
    49094913        sage: RealNumber('.000000000000000000000000000000001').prec()
    49104914        53
    49114915        sage: RealNumber('-.000000000000000000000000000000001').prec()
    49124916        53
     4917   
     4918    Unless the value is exactly zero::
     4919
     4920        sage: RealNumber('.00000000000000000000000000000000000').prec()
     4921        120
     4922        sage: RealNumber('0.0000000000000000000000000000000000').prec()
     4923        120
     4924
     4925    TESTS:
     4926   
     4927    The placements of the decimal points and signs don't affect the precision::
     4928   
     4929        sage: RealNumber('.11111111111111111111111111111111111').prec()
     4930        120
     4931        sage: RealNumber('1.1111111111111111111111111111111111').prec()
     4932        120
     4933        sage: RealNumber('11111111111111111111111111111111111.').prec()
     4934        120
     4935        sage: RealNumber('11111111111111111111111111111111111').prec()
     4936        120
     4937        sage: RealNumber('+11111111111111111111111111111111111').prec()
     4938        120
     4939        sage: RealNumber('-11111111111111111111111111111111111').prec()
     4940        120
     4941       
     4942    Make sure the the string representation agrees with the input::
     4943   
     4944        sage: s = 1.1111111111111111111111111111111111
     4945        sage: parent(s) is parent(RealNumber(str(s)))
     4946        True
    49134947    """
    4914     if not isinstance(s, str):
     4948    cdef int i, sigfigs
     4949   
     4950    if isinstance(s, float):
     4951        return RealNumber(RR, s)
     4952    elif isinstance(s, RealNumber):
     4953        return s
     4954    elif not isinstance(s, str):
    49154955        s = str(s)
    49164956       
    4917     if base == 10 and min_prec == 53 and len(s) <= 15:
     4957    if base >= 10 and min_prec == 53 and len(s) <= 15 and pad == 0:
     4958        # Most common case by far.
    49184959        R = RR
    49194960   
    49204961    else:
     
    49274968        else:
    49284969            mantissa = s
    49294970           
    4930         #Find the first nonzero entry in rest
    4931         sigfigs = 0
     4971        #Find the first nonzero entry in mantissa
     4972        sigfigs = len(mantissa)
    49324973        for i in range(len(mantissa)):
    4933             if mantissa[i] != '.' and mantissa[i] != '0' and mantissa[i] != '-':
    4934                 sigfigs = len(mantissa) - i
     4974            if mantissa[i] == '0':
     4975                sigfigs -= 1
     4976            elif mantissa[i] not in ".+-":
    49354977                break
    4936        
    4937         if '.' in mantissa and mantissa[:2] != '0.':
     4978        else:
     4979            # Must be 0.00000000000000...0
     4980            sigfigs = len(mantissa)
     4981
     4982        if mantissa[0] in '-+':
    49384983            sigfigs -= 1
     4984        if '.' in mantissa:
     4985            sigfigs -= 1
     4986        # This is so the input matches with the string representation.
     4987        sigfigs += 1
    49394988       
    49404989        if base == 10:
    49414990            bits = int(3.32192*sigfigs)+1
  • sage/symbolic/expression.pyx

    diff -r 43d7e32917c3 -r d6c95f7280a9 sage/symbolic/expression.pyx
    a b  
    55565556            sage: maxima('cosh(1.0)')
    55575557            1.54308063481524...
    55585558            sage: SR(1.00000000000000000000000000).cosh()
    5559             1.5430806348152437784779056
     5559            1.54308063481524377847790562
    55605560            sage: SR(RIF(1)).cosh()
    55615561            1.543080634815244?
    55625562