# Module math_pos

- Description
- Data Types
- Function Index
- Function Details

Implements mathematical operations on numbers in positional notations represented by lists, i.e.

Copyright © 2011 Zuse Institute Berlin

Version: $Id$

Authors: Nico Kruber (`kruber@zib.de`).

## Description

Implements mathematical operations on numbers in positional notations represented by lists, i.e. [1,2,3] with Base 10 equals 1*10^0 + 2*10^-1 + 3*10^-2. Note: valid list elements are: 0..(Base-1).

## Data Types

### position_var()

    position_var() = [non_neg_integer()]

## Function Index

divide/3 | A / Divisor (with rounding to nearest integer not larger than the result in the last component).
from_decimal/2 | Converts a (decimal, non-negative) integer to a position var with the given Base.
make_same_length/3 | Bring two lists to the same length by appending or prepending zeros.
make_same_length/4 | Bring two lists to the same length by appending or prepending at least MinAdd zeros.
minus/3 | A - B.
multiply/3 | A * Factor, if Factor is a non-negative integer cutting off any carry forwards.
multiply/4 | A * Factor, if Factor is a non-negative integer.
plus/3 | A + B.
remove_zeros/3 | Remove leading or trailing 0's.
to_decimal/2 | Converts a position var with the given Base to a (decimal, non-negative) integer.

## Function Details

### plus/3

    plus(A :: position_var(),
         B :: position_var(),
         Base :: pos_integer()) ->
            position_var()

A + B

### minus/3

    minus(A :: position_var(),
          B :: position_var(),
          Base :: pos_integer()) ->
             position_var()

A - B

### multiply/3

    multiply(A :: position_var(),
             Factor :: non_neg_integer(),
             Base :: pos_integer()) ->
                position_var()

A * Factor, if Factor is a non-negative integer cutting off any carry forwards.

### multiply/4

    multiply(A :: position_var(),
             Factor :: non_neg_integer(),
             Base :: pos_integer(),
             Cut :: cutoff) ->
                {Prod :: position_var(), Added :: 0}

A * Factor, if Factor is a non-negative integer.

### divide/3

    divide(A :: position_var(),
           Divisor :: pos_integer(),
           Base :: pos_integer()) ->
              position_var()

A / Divisor (with rounding to nearest integer not larger than the result in the last component). Divisor must be a positive integer.

### make_same_length/3

    make_same_length(A :: position_var(),
                     B :: position_var(),
                     AddTo :: front | back) ->
                        {A :: position_var(),
                         B :: position_var(),
                         ALen :: non_neg_integer(),
                         BLen :: non_neg_integer(),
                         AddedToA :: non_neg_integer(),
                         AddedToB :: non_neg_integer()}

Bring two lists to the same length by appending or prepending zeros.

### make_same_length/4

    make_same_length(A :: position_var(),
                     B :: position_var(),
                     AddTo :: front | back,
                     MinAdd :: non_neg_integer()) ->
                        {A :: position_var(),
                         B :: position_var(),
                         ALen :: non_neg_integer(),
                         BLen :: non_neg_integer(),
                         AddedToA :: non_neg_integer(),
                         AddedToB :: non_neg_integer()}

Bring two lists to the same length by appending or prepending at least MinAdd zeros.

### remove_zeros/3

    remove_zeros(A :: position_var(),
                 RemoveFrom :: front | back,
                 MaxToRemove :: non_neg_integer() | all) ->
                    A :: position_var()

Remove leading or trailing 0's.

### from_decimal/2

    from_decimal(X :: non_neg_integer(), Base :: pos_integer()) ->
                    position_var()

Converts a (decimal, non-negative) integer to a position var with the given Base.

### to_decimal/2

    to_decimal(X :: position_var(), Base :: pos_integer()) ->
                  non_neg_integer()

Converts a position var with the given Base to a (decimal, non-negative) integer.

Generated by EDoc, Feb 29 2016, 16:12:18.