Skip to main content

LIBrary for TGMK (Tebi-Gibi-Mebi-Kibi), a 1024-base integer representation

Project description

Help on package libtgmk:

NAME
    libtgmk - LIBrary for TGMK (Tebi-Gibi-Mebi-Kibi), a 1024-base integer representation

DESCRIPTION

    CONTENT

        1. Installation
        2. Help
        3. Definitions
        4. Implementation
        5. Exceptions
        6. History

    1. INSTALLATION

    From terminal type:

        $ pip3 install libtgmk

    2. HELP

    From terminal type:

        $ pydoc libtgmk

    or, from a Python IDE:

        >>> import libtgmk
        >>> help(libtgmk)

    3. DEFINITIONS

    "TGMK"  (Tebi-Gibi-Mebi-Kibi)  is  a  human-readable  lossless case-insensitive 1024-base
    integer representation, suitable for bits and bytes.

    A "TGMK literal" is a string containing:

        • zero or more leading blanks
        • an optional ('+' or '-') "sign"
        • one or more "1024-base-digits", each made by:
            • a  "mantissa", a string of one or more decimal digits, representing an unsigned
              decimal integer constant, as '0', '1' or '100000'.
            • a "characteristic", a letter in 'KMGTPEZY' (or 'kmgtpezy')
        • zero or more trailing blanks

    Only last (rightmost) 1024-base-digit can lack characteristic, meaning unities.

    Characteristic letters have the following well-known meanings:

        ╔══════╤══════╤════╤═════╤════╤══════════════════╤═══════╤═════════════════════════╗
        ║LETTER│PREFIX│BITS│BYTES│LOG2│      LOG10       │LOG1024│          VALUE          ║
        ╟──────┼──────┼────┼─────┼────┼──────────────────┼───────┼─────────────────────────╢
        ║'K'   │kibi- │Kib │KiB  │10.0│ 3.010299956639812│    1.0│                     1024║
        ║'M'   │mebi- │Mib │MiB  │20.0│ 6.020599913279624│    2.0│                  1048576║
        ║'G'   │gibi- │Gib │GiB  │30.0│ 9.030899869919436│    3.0│               1073741824║
        ║'T'   │tebi- │Tib │TiB  │40.0│12.041199826559248│    4.0│            1099511627776║
        ║'P'   │pebi- │Pib │PiB  │50.0│ 15.05149978319906│    5.0│         1125899906842624║
        ║'E'   │exbi- │Eib │EiB  │60.0│ 18.06179973983887│    6.0│      1152921504606846976║
        ║'Z'   │zebi- │Zib │ZiB  │70.0│21.072099696478684│    7.0│   1180591620717411303424║
        ║'Y'   │yobi- │Yib │YiB  │80.0│24.082399653118497│    8.0│1208925819614629174706176║
        ╚══════╧══════╧════╧═════╧════╧══════════════════╧═══════╧═════════════════════════╝

    Characteristic letters must appear left to right in strictly decreasing value order:

        • '3m5k7' is ok, its value is 3 * 1024 ** 2 + 5 * 1024 + 7 == 3150855
        • '5k3m7' is wrong
        • '5k3k7' is wrong too

    In mantissas one or more leading zeros are allowed, while commas are not:

        • '04096m' is ok
        • '4,096m' is wrong

    A TGMK literal is "normalized" if:

        • no leading or trailing blanks are present
        • sign is '-' for negative numbers, absent for zero or positive numbers
        • mantissas are between 1 and 1023, with no leading zeros, with two exceptions:
            • normalized TGMK literal for zero is '0'
            • for very large numbers the mantissa preceding 'Y' can get any value
        • characteristic letters are always uppercase

    4. IMPLEMENTATION

    libtgmk implements TGMK format by two functions, tgmk2int() and int2tgmk():

        • tgmk2int(s) converts TGMK literal s (normalized or not) into integer
        • int2tgmk(i) converts integer i into a normalized TGMK literal

    For  each  integer  i,  int2tgmk(i) never raises an exception, while tgmk2int(s) raises a
    ValueError exception if string s is not a correct TGMK literal.

    For  each integer i, tgmk2int(int2tgmk(i)) == i, while int2tgmk(tgmk2int(s)) == s only if
    string s is a normalized TGMK literal.

    Three additional functions are:

        • tgmk2tgmk(s)  converts  TGMK  literal  s (normalized or not) into a normalized TGMK
          literal
        • istgmk(s) checks if s is a correct TGMK literal or not
        • isnormtgmk(s) checks if s is a correct normalized TGMK literal or not

    5. EXCEPTIONS

        • TypeError if argument of int2tgmk() is not an int
        • TypeError if argument of tgmk2int or tgmk2tgmk is not a str
        • ValueError  if argument of tgmk2int or tgmk2tgmk is a str but is not a correct TGMK
          literal

    6. HISTORY

        • libtgmk 0.4.5
            • updated: documentation

        • libtgmk 0.4.4
            • updated: documentation

        • libtgmk 0.4.3
            • updated: documentation
            • rewritten: pyproject.toml, now compliant with flit >= 3.2

        • libtgmk 0.4.2
            • rewritten: tgmk2int() and int2tgmk() functions
            • added: tgmk2tgmk(), istgmk() and isnormtgmk() functions

        • libtgmk 0.4.1
            • first version on Pypi

PACKAGE CONTENTS


FUNCTIONS
    int2tgmk(i)
        convert integer {i} into a normalized TGMK literal

            >>> int2tgmk(3000 * 1024 + 5)
            '2M952K5'

    isnormtgmk(s)
        is {s} a normalized TGMK literal?

            >>> isnormtgmk('3000k5') # 3000 > 1023, 'k' is lowercase
            False

    istgmk(s)
        is {s} a TGMK literal?

            >>> istgmk('3000k5')
            True

    tgmk2int(s)
        convert TGMK literal {s} (normalized or not) into an integer

            >>> tgmk2int('3000k5')
            3072005

    tgmk2tgmk(s)
        convert TGMK literal {s} (normalized or not) into a normalized TGMK literal

            >>> tgmk2tgmk('   0003000k0005   ')
            '2M952K5'

DATA
    __all__ = ['tgmk2int', 'int2tgmk', 'tgmk2tgmk', 'istgmk', 'isnormtgmk'...

VERSION
    0.4.5

FILE
    /home/xxxx/Documents/pypi/libtgmk/libtgmk/__init__.py


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

libtgmk-0.4.5.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

libtgmk-0.4.5-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file libtgmk-0.4.5.tar.gz.

File metadata

  • Download URL: libtgmk-0.4.5.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for libtgmk-0.4.5.tar.gz
Algorithm Hash digest
SHA256 a5d52d1dde696864be9092a319174a10cabb13502bd29867a4712620c1f9b6ca
MD5 987425b1ef065c4077a4b9af00c4df59
BLAKE2b-256 7c7bc1c4cd3d9afe0e135fe80c7bfc787eef0caf4ac3a22233d0bd8eac8d4816

See more details on using hashes here.

File details

Details for the file libtgmk-0.4.5-py3-none-any.whl.

File metadata

  • Download URL: libtgmk-0.4.5-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for libtgmk-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 70258f47dd7798cf2a67ba413db45b90b320170b04b99a5cca8a4944bffd930f
MD5 957324cb85858f839bb689fcf68df846
BLAKE2b-256 931c0d996ef03d976e5006754ed648de7a0cfe464699f870acf7241139f436bc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page