Révision 179 pobysoPythonSage/src/sageSLZ/sageNumericalOperations.sage

sageNumericalOperations.sage (revision 179)
1 1
print "sageNumericalOperations: loading..."
2 2

  
3

  
3 4
def sno_abs_is_power_of_two(number):
4 5
    """
5 6
    Check if the absolute value of a number is power of 2.
......
9 10
    return is_power_of_two(abs(number))
10 11
# End sno_abs_is_power_of_two(number):
11 12

  
13
def sno_float_to_rat_pow_of_two_denom(number):
14
    """
15
    Convert a floating-point number into a rational where the denominator
16
    is a power of two
17
    """
18
    ## Argument checking.
19
    if not number.is_real():
20
        return None
21
    #
22
    (sign, mantissa, exponent) = number.sign_mantissa_exponent()
23
    #print sign, mantissa, exponent
24
    precision = number.prec()
25
    if exponent < 0:
26
        denomFactorExp = -exponent
27
    else:
28
        denomFactorExp = -exponent
29
    if sign == 1:
30
        return mantissa / 2^(denomFactorExp)
31
    else:
32
        return -mantissa / 2^(denomFactorExp)
33
        
34
        
35

  
12 36
print "\t...sageNumericalOperations loaded."

Formats disponibles : Unified diff