Typedefs | Functions
vnl_bignum.cxx File Reference
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <vector>
#include <iostream>
#include "vnl_bignum.h"
#include <vnl/vnl_math.h>

Go to the source code of this file.

Typedefs

typedef unsigned short Counter
 
typedef unsigned short Data
 

Functions

std::istream & operator>> (std::istream &is, vnl_bignum &x)
 Reads a vnl_bignum from a stream. More...
 
std::ostream & operator<< (std::ostream &os, const vnl_bignum &b)
 Formatted output for bignum. More...
 
std::string & vnl_bignum_to_string (std::string &s, const vnl_bignum &b)
 Convert the number to a decimal representation in a string. More...
 
vnl_bignumvnl_bignum_from_string (vnl_bignum &b, const std::string &s)
 Convert the number from a decimal representation in a string. More...
 
unsigned int ctox (int c)
 convert hex character to integer hex value (ASCII or EBCDIC). More...
 
void add (const vnl_bignum &b1, const vnl_bignum &b2, vnl_bignum &sum)
 add two non-infinite vnl_bignum values and save their sum. More...
 
void increment (vnl_bignum &bnum)
 Add 1 to bnum (unsigned, non-infinite). More...
 
void subtract (const vnl_bignum &bmax, const vnl_bignum &bmin, vnl_bignum &diff)
 subtract bmin from bmax (unsigned, non-infinite), result in diff. More...
 
void decrement (vnl_bignum &bnum)
 Subtract 1 from bnum (unsigned, non-infinite, non-zero). More...
 
int magnitude_cmp (const vnl_bignum &b1, const vnl_bignum &b2)
 compare absolute values of two vnl_bignums. More...
 
void multiply_aux (const vnl_bignum &b, Data d, vnl_bignum &prod, Counter i)
 multiply a non-infinite vnl_bignum by a "single digit". More...
 
Data normalize (const vnl_bignum &b1, const vnl_bignum &b2, vnl_bignum &u, vnl_bignum &v)
 normalize two vnl_bignums. More...
 
void divide_aux (const vnl_bignum &b1, Data d, vnl_bignum &q, Data &r)
 divide a vnl_bignum by a "single digit". More...
 
Data estimate_q_hat (const vnl_bignum &u, const vnl_bignum &v, Counter j)
 estimate next dividend. More...
 
Data multiply_subtract (vnl_bignum &u, const vnl_bignum &v, Data q_hat, Counter j)
 calculate u - v*q_hat. More...
 
void divide (const vnl_bignum &b1, const vnl_bignum &b2, vnl_bignum &q, vnl_bignum &r)
 divide b2 into b1, getting quotient q and remainder r. More...
 
vnl_bignum left_shift (const vnl_bignum &b1, int l)
 left shift (arithmetic) non-infinite vnl_bignum by positive number. More...
 
vnl_bignum right_shift (const vnl_bignum &b1, int l)
 right shift (arithmetic) non-infinite vnl_bignum by positive number. More...
 

Typedef Documentation

◆ Counter

typedef unsigned short Counter

Definition at line 15 of file vnl_bignum.cxx.

◆ Data

typedef unsigned short Data

Definition at line 16 of file vnl_bignum.cxx.

Function Documentation

◆ add()

void add ( const vnl_bignum b1,
const vnl_bignum b2,
vnl_bignum sum 
)

add two non-infinite vnl_bignum values and save their sum.

Definition at line 887 of file vnl_bignum.cxx.

◆ ctox()

unsigned int ctox ( int  c)

convert hex character to integer hex value (ASCII or EBCDIC).

  • Inputs: character representation of a hex number
  • Outputs: integer value of the hex number

Definition at line 802 of file vnl_bignum.cxx.

◆ decrement()

void decrement ( vnl_bignum bnum)

Subtract 1 from bnum (unsigned, non-infinite, non-zero).

Definition at line 969 of file vnl_bignum.cxx.

◆ divide()

void divide ( const vnl_bignum b1,
const vnl_bignum b2,
vnl_bignum q,
vnl_bignum r 
)

divide b2 into b1, getting quotient q and remainder r.

(Refer to Knuth, V.2, Section 4.3.1, Algorithm D for details. This function implements Algorithm D.)

  • Inputs: references to a vnl_bignum dividend b1, divisor b2, quotient q, and remainder r.

Definition at line 1187 of file vnl_bignum.cxx.

◆ divide_aux()

void divide_aux ( const vnl_bignum b1,
Data  d,
vnl_bignum q,
Data r 
)

divide a vnl_bignum by a "single digit".

(Refer to Knuth, V.2, Section 4.3.2, exercise 16 for details. A digit here is one data element in the radix 2**2.)

  • Inputs: reference to vnl_bignum dividend, single digit divisor d, vnl_bignum quotient, and single digit remainder r

Definition at line 1062 of file vnl_bignum.cxx.

◆ estimate_q_hat()

Data estimate_q_hat ( const vnl_bignum u,
const vnl_bignum v,
Counter  j 
)

estimate next dividend.

(Refer to Knuth, V.2, Section 4.3.1, Algorithm D for details. This function estimates how many times v goes into u, starting at u's jth digit. A digit here is actually a data element, thought of as being in the radix 2**2.)

  • Inputs: reference to vnl_bignum dividend and divisor and starting digit j
  • Outputs: estimated number of times v goes into u

Definition at line 1082 of file vnl_bignum.cxx.

◆ increment()

void increment ( vnl_bignum bnum)

Add 1 to bnum (unsigned, non-infinite).

Definition at line 928 of file vnl_bignum.cxx.

◆ left_shift()

vnl_bignum left_shift ( const vnl_bignum b1,
int  l 
)

left shift (arithmetic) non-infinite vnl_bignum by positive number.

  • Inputs: reference to vnl_bignum, positive shift value
  • Outputs: vnl_bignum, multiplied by the corresponding power of two

Definition at line 1246 of file vnl_bignum.cxx.

◆ magnitude_cmp()

int magnitude_cmp ( const vnl_bignum b1,
const vnl_bignum b2 
)

compare absolute values of two vnl_bignums.

Outputs: result of comparison: -1 if abs(b1) < abs(b2) 0 if abs(b1) == abs(b2) +1 if abs(b1) > abs(b2)

Definition at line 988 of file vnl_bignum.cxx.

◆ multiply_aux()

void multiply_aux ( const vnl_bignum b,
Data  d,
vnl_bignum prod,
Counter  i 
)

multiply a non-infinite vnl_bignum by a "single digit".

  • Inputs: vnl_bignum reference, single word multiplier, reference to the product, and index of starting storage location to use in product

Definition at line 1009 of file vnl_bignum.cxx.

◆ multiply_subtract()

Data multiply_subtract ( vnl_bignum u,
const vnl_bignum v,
Data  q_hat,
Counter  j 
)

calculate u - v*q_hat.

(Refer to Knuth, V. 2, Section 4.3.1, Algorithm D for details. A digit here is a data element, thought of as being in the radix 2**2.)

  • Inputs: reference to vnl_bignum dividend, divisor, estimated result, and index into jth digit of dividend
  • Outputs: true number of times v goes into u

Definition at line 1129 of file vnl_bignum.cxx.

◆ normalize()

Data normalize ( const vnl_bignum b1,
const vnl_bignum b2,
vnl_bignum u,
vnl_bignum v 
)

normalize two vnl_bignums.

(Refer to Knuth, V.2, Section 4.3.1, Algorithm D for details. A digit here is one data element in the radix 2**2.)

  • Inputs: references to two vnl_bignums b1, b2
  • Outputs: their normalized counterparts u and v, and the integral normalization factor used

Definition at line 1045 of file vnl_bignum.cxx.

◆ operator<<()

VNL_EXPORT std::ostream & operator<< ( std::ostream &  os,
const vnl_bignum b 
)

Formatted output for bignum.

formatted output.

Definition at line 617 of file vnl_bignum.cxx.

◆ operator>>()

VNL_EXPORT std::istream & operator>> ( std::istream &  is,
vnl_bignum x 
)

Reads a vnl_bignum from a stream.

simple input.

Definition at line 354 of file vnl_bignum.cxx.

◆ right_shift()

vnl_bignum right_shift ( const vnl_bignum b1,
int  l 
)

right shift (arithmetic) non-infinite vnl_bignum by positive number.

  • Inputs: reference to vnl_bignum, positive shift value
  • Outputs: vnl_bignum, divided by the corresponding power of two

Definition at line 1284 of file vnl_bignum.cxx.

◆ subtract()

void subtract ( const vnl_bignum bmax,
const vnl_bignum bmin,
vnl_bignum diff 
)

subtract bmin from bmax (unsigned, non-infinite), result in diff.

Definition at line 947 of file vnl_bignum.cxx.

◆ vnl_bignum_from_string()

VNL_EXPORT vnl_bignum & vnl_bignum_from_string ( vnl_bignum b,
const std::string &  s 
)

Convert the number from a decimal representation in a string.

Definition at line 667 of file vnl_bignum.cxx.

◆ vnl_bignum_to_string()

VNL_EXPORT std::string & vnl_bignum_to_string ( std::string &  s,
const vnl_bignum b 
)

Convert the number to a decimal representation in a string.

Definition at line 643 of file vnl_bignum.cxx.