Révision 119 pobysoPythonSage/src/sageSLZ/sageSLZ.sage

sageSLZ.sage (revision 119)
5 5
- S.T. (2013-08): initial version
6 6

  
7 7
Examples:
8
    TOD
8

  
9
TODO::
9 10
"""
10 11
print "sageSLZ loading..."
11 12
#
......
86 87

  
87 88
# End slz_check_htr_value.
88 89
#
90
def slz_compute_binade_bounds(number, emin):
91
    """
92
    For given "real number", compute the bounds of the binade it belongs to.
93
    TODO::
94
        Deal with the emax exponent.
95
    """
96
    RF = number.parent()
97
    precision = RF.precision()
98
    RRF = RealField(2 * precision)
99
    if number == 0:
100
        return (RF(0),RF(2^(emin)) - RF(2^(emin-precision)))
101
    l2 = RRF(number).abs().log2()
102
    offset = int(l2)
103
    if l2 >= 0:
104
        if number >= 0:
105
            lb = RF(2^offset)
106
            ub = RF(2^(offset + 1) - 2^(-precision+offset+1))
107
        else: #number < 0
108
            lb = -RF(2^(offset + 1) - 2^(-precision+offset+1))
109
            ub = -RF(2^offset)
110
    else: # log2 < 0
111
        if l2 < emin: # Denormal
112
            print "Denormal:", l2
113
            if number >= 0:
114
                lb = RF(0)
115
                ub = RF(2^(emin)) - RF(2^(emin-precision))
116
            else: # number <= 0
117
                lb = - RF(2^(emin)) + RF(2^(emin-precision))
118
                ub = RF(0)
119
        elif l2 > emin: # Normal number other than +/-2^emin.
120
            if number >= 0:
121
                lb = RF(2^(offset-1))
122
                ub = RF(2^(offset)) - RF(2^(-precision+offset))
123
            else: # number < 0
124
                lb = -RF(2^(offset) - 2^(-precision+offset))
125
                ub = -RF(2^(offset-1))
126
        else: # +/-2^emin
127
            if number >= 0:
128
                lb = RF(2^(offset))
129
                ub = RF(2^(offset+1)) - RF(2^(-precision+offset+1))
130
            else: # number < 0
131
                lb = -RF(2^(offset+1) - 2^(-precision+offset+1))
132
                ub = -RF(2^(offset))
133
    return (lb, ub)
134
# End slz_compute_binade_bounds
135
#
89 136
def slz_compute_polynomial_and_interval(functionSo, degreeSo, lowerBoundSa, 
90 137
                                        upperBoundSa, approxPrecSa, 
91 138
                                        sollyaPrecSa=None):

Formats disponibles : Unified diff