Package sympycore :: Package arithmetic :: Package mpmath :: Package lib :: Module numerals
[hide private]
[frames] | no frames]

Module numerals

source code

Provides varios conversation functions for numerals.

Functions [hide private]
 
make_fixed(s, prec)
Convert a floating-point number to a fixed-point big integer
source code
call graph 
 
bin_to_radix(x, xbits, base, bdigits)
Radix conversion for fixed-point numbers.
source code
call graph 
 
small_numeral(n, base=10, digits='0123456789abcdefghijklmnopqrstuvwxyz')
Return the string numeral of a positive integer in an arbitrary base.
source code
call graph 
 
numeral(n, base=10, size=0, digits='0123456789abcdefghijklmnopqrstuvwxyz')
Represent the integer n as a string of digits in the given base.
source code
call graph 
 
to_digits_exp(s, dps)
Helper function for representing the floating-point number s as a decimal with dps places.
source code
call graph 
 
to_str(s, dps)
Convert a raw mpf to a decimal floating-point literal with at most `dps` decimal digits in the mantissa (not counting extra zeros that may be inserted for visual purposes).
source code
call graph 
 
str_to_man_exp(x, base=10) source code
call graph 
 
from_str(x, prec, rounding)
Create a raw mpf from a decimal literal, rounding in the specified direction if the input number cannot be represented exactly as a binary floating-point number with the given number of bits.
source code
call graph 
 
from_bstr(x) source code
 
to_bstr(x) source code
Variables [hide private]
  stddigits = '0123456789abcdefghijklmnopqrstuvwxyz'
  special_str = {'+inf': ('+inf', 0, -1), '-inf': ('-inf', 0, -1...
Function Details [hide private]

bin_to_radix(x, xbits, base, bdigits)

source code 
call graph 
Radix conversion for fixed-point numbers. That is, convert x * 2**xbits to floor(x * 10**bdigits).

small_numeral(n, base=10, digits='0123456789abcdefghijklmnopqrstuvwxyz')

source code 
call graph 
Return the string numeral of a positive integer in an arbitrary base. Most efficient for small input.

numeral(n, base=10, size=0, digits='0123456789abcdefghijklmnopqrstuvwxyz')

source code 
call graph 

Represent the integer n as a string of digits in the given base. Recursive division is used to make this function about 3x faster than Python's str() for converting integers to decimal strings.

The 'size' parameters specifies the number of digits in n; this number is only used to determine splitting points and need not be exact.

to_digits_exp(s, dps)

source code 
call graph 

Helper function for representing the floating-point number s as a decimal with dps places. Returns (sign, string, exponent) containing '' or '-', the decimal digits as a string, and an integer for the decimal exponent.

If inexact, the decimal representation is rounded toward zero.

to_str(s, dps)

source code 
call graph 

Convert a raw mpf to a decimal floating-point literal with at most `dps` decimal digits in the mantissa (not counting extra zeros that may be inserted for visual purposes).

The literal is formatted so that it can be parsed back to a number by to_str, float() or Decimal().

from_str(x, prec, rounding)

source code 
call graph 

Create a raw mpf from a decimal literal, rounding in the specified direction if the input number cannot be represented exactly as a binary floating-point number with the given number of bits. The literal syntax accepted is the same as for Python floats.

TODO: the rounding does not work properly for large exponents.

Variables Details [hide private]

special_str

Value:
{'+inf': ('+inf', 0, -1),
 '-inf': ('-inf', 0, -1),
 'inf': ('+inf', 0, -1),
 'nan': ('nan', 0, -1)}