root / pobysoPythonSage / src / sageSLZ / sageNumericalOperations.sage @ 232
Historique | Voir | Annoter | Télécharger (892 octet)
| 1 |
print "sageNumericalOperations: loading..." |
|---|---|
| 2 |
|
| 3 |
|
| 4 |
def sno_abs_is_power_of_two(number): |
| 5 |
""" |
| 6 |
Check if the absolute value of a number is power of 2. |
| 7 |
The built-in is_power_of_two, works with many kinds of numbers but |
| 8 |
returns false for negative ones. |
| 9 |
""" |
| 10 |
return is_power_of_two(abs(number)) |
| 11 |
# End sno_abs_is_power_of_two(number): |
| 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 sign == 1: |
| 26 |
return mantissa / 2^(-exponent) |
| 27 |
else: |
| 28 |
return -mantissa / 2^(-exponent) |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
print "\t...sageNumericalOperations loaded." |