Package python :: Module encoder
[hide private]
[frames] | no frames]

Module encoder

source code

Functions [hide private]
 
_frexp(f)
This is q think wrapper around python's frexp that returns a mantissa and exponent in a form that is a little more convenient for the the fileio module.
source code
 
_ldexp(m, e)
This function performs the inverse of _frexp.
source code
 
_bitstring_to_charstring(bit_string)
This function takes a bit_string (i.e.
source code
 
_charstring_to_bitstring(char_string)
This function takes a character string (i.e.
source code
 
_encode_mantissa_as_bitstring(mant)
This is expecting an integer.
source code
 
_encode_exponent_as_bitstring(exponent)
This is expecting an integer.
source code
 
encode_unsigned(i)
This function 'encodes' both int and long types and returns a string that can be fed to the pyhton file's write method.
source code
 
decode_unsigned(char_string)
The function decodes a string of characters and returns the integer (or long) value.
source code
 
encode_float(f)
This function translates a float to its 8 byte character string repesentation so that python's file write method can write it.
source code
 
decode_float(s)
This function translates an 8 byte character string repesentation to a float.
source code
Function Details [hide private]

_frexp(f)

source code 

This is q think wrapper around python's frexp that returns a mantissa and exponent in a form that is a little more convenient for the the fileio module. Namely the exponent offset form is preferable since there's now only one sign to worry about. This greatly simplifies file i/o. The mantissa is converted to an integer (* 10**15 to minimize precision loss and fits into 52 bits) and the exponent is shifted by 1023 to guarantee it is an unsigned integer and fits into 11 bits.

Parameters:
  • f - The float value to be coverted to be decomposed into mantissa and exponent.

_ldexp(m, e)

source code 

This function performs the inverse of _frexp. Given a mantissa and exponent, it returns the float representation.

Parameters:
  • m - mantissa assumed to be type long.
  • e - exponent assumed to be type int.

_bitstring_to_charstring(bit_string)

source code 

This function takes a bit_string (i.e. '10010011') and returns a string of characters ('“' in this example) that can be fed to python's file write method.

_charstring_to_bitstring(char_string)

source code 

This function takes a character string (i.e. '“') and returns a string of bits ('10010011' in this example) that can be converted to the correct type.

_encode_mantissa_as_bitstring(mant)

source code 

This is expecting an integer. The purpose of this function is to return the bit_string representation of the mantissa. The length of the string is 52 characters long and is meant to be combined with the 11 bit exponent and 1 sign bit to form a 64 bit string representation of a double precision float.

_encode_exponent_as_bitstring(exponent)

source code 

This is expecting an integer. The purpose of this function is to return the bit_string representation of the exponent. The length of the string is 11 characters long and is meant to be combined with the 52 bit exponent and 1 sign bit to form a 64 bit string representation of a double precision float.

encode_float(f)

source code 

This function translates a float to its 8 byte character string repesentation so that python's file write method can write it. The 64 bit representation is a follows:

  1. 1 bit for the sign
  2. 11 bits for the exponent
  3. 52 bits for the mantissa

So read as a string the SIGN is in the 0th position, the EXPONENT is 1-11, and the MANTISSA is 12-52. m / 10.**15, e - 1023 f = (-1)**SIGN * (MANTISSA/10**15) * 2**(EXPONENT - 1023 )

decode_float(s)

source code 

This function translates an 8 byte character string repesentation to a float. See the coreresponding _frexp function for the byte layout and interpretation.