Infinite precision integers. More...
#include <vnl_bignum.h>
Public Member Functions | |
| vnl_bignum () | |
| Creates a zero vnl_bignum. More... | |
| vnl_bignum (long) | |
| Creates a vnl_bignum from a long integer. More... | |
| vnl_bignum (unsigned long) | |
| Creates a vnl_bignum from an unsigned long integer. More... | |
| vnl_bignum (int) | |
| Creates a vnl_bignum from an integer. More... | |
| vnl_bignum (unsigned int) | |
| Creates a vnl_bignum from an unsigned integer. More... | |
| vnl_bignum (float) | |
| Creates a vnl_bignum from a single-precision floating point number. More... | |
| vnl_bignum (double) | |
| Creates a vnl_bignum from a double floating point number. More... | |
| vnl_bignum (long double) | |
| Creates a vnl_bignum from a "long double" floating point number. More... | |
| vnl_bignum (vnl_bignum const &) | |
| Copies the contents of vnl_bignum b. More... | |
| vnl_bignum (const char *) | |
| Creates a vnl_bignum from the character string representation. More... | |
| ~vnl_bignum () | |
| Frees space for vnl_bignum. More... | |
| operator short () const | |
| Implicit conversion from a vnl_bignum to a short. More... | |
| operator int () const | |
| Implicit conversion from a vnl_bignum to an int. More... | |
| operator long () const | |
| Implicit conversion from a vnl_bignum to a long. More... | |
| operator float () const | |
| Implicit conversion from a vnl_bignum to a float. More... | |
| operator double () const | |
| Implicit conversion from a vnl_bignum to a double. More... | |
| operator long double () const | |
| Implicit conversion from a vnl_bignum to a long double. More... | |
| operator short () | |
| operator int () | |
| operator long () | |
| operator float () | |
| operator double () | |
| operator long double () | |
| vnl_bignum | operator- () const |
| Returns the negation of a vnl_bignum. More... | |
| vnl_bignum | operator+ () const |
| vnl_bignum & | operator= (const vnl_bignum &) |
| Copies rhs vnl_bignum to lhs vnl_bignum. More... | |
| vnl_bignum | operator<< (int l) const |
| Shifts bignum to the left l digits. More... | |
| vnl_bignum | operator>> (int l) const |
| Shifts bignum to the right l digits. More... | |
| vnl_bignum | operator+ (vnl_bignum const &r) const |
| Adds two vnl_bignums, and returns new sum. More... | |
| vnl_bignum & | operator+= (vnl_bignum const &r) |
| vnl_bignum & | operator-= (vnl_bignum const &r) |
| vnl_bignum & | operator *= (vnl_bignum const &r) |
| Multiplies this with a vnl_bignum. More... | |
| vnl_bignum & | operator/= (vnl_bignum const &r) |
| Divides this by a vnl_bignum. More... | |
| vnl_bignum & | operator%= (vnl_bignum const &r) |
| Divides this by a vnl_bignum and replaces this by remainder. More... | |
| vnl_bignum & | operator<<= (int l) |
| vnl_bignum & | operator>>= (int l) |
| vnl_bignum & | operator++ () |
| prefix increment (++b). More... | |
| vnl_bignum & | operator-- () |
| decrement. More... | |
| vnl_bignum | operator++ (int) |
| postfix increment (b++). More... | |
| vnl_bignum | operator-- (int) |
| decrement. More... | |
| bool | operator== (vnl_bignum const &) const |
| Two vnl_bignums are equal if and only if they have the same integer representation. More... | |
| bool | operator< (vnl_bignum const &) const |
| Compares two vnl_bignums. More... | |
| bool | operator!= (vnl_bignum const &r) const |
| bool | operator> (vnl_bignum const &r) const |
| bool | operator<= (vnl_bignum const &r) const |
| bool | operator>= (vnl_bignum const &r) const |
| bool | operator== (long r) const |
| bool | operator!= (long r) const |
| bool | operator< (long r) const |
| bool | operator> (long r) const |
| bool | operator<= (long r) const |
| bool | operator>= (long r) const |
| bool | operator== (int r) const |
| bool | operator!= (int r) const |
| bool | operator< (int r) const |
| bool | operator> (int r) const |
| bool | operator<= (int r) const |
| bool | operator>= (int r) const |
| bool | operator== (double r) const |
| bool | operator!= (double r) const |
| bool | operator< (double r) const |
| bool | operator> (double r) const |
| bool | operator<= (double r) const |
| bool | operator>= (double r) const |
| bool | operator== (long double r) const |
| bool | operator!= (long double r) const |
| bool | operator< (long double r) const |
| bool | operator> (long double r) const |
| bool | operator<= (long double r) const |
| bool | operator>= (long double r) const |
| vnl_bignum | abs () const |
| bool | is_infinity () const |
| bool | is_plus_infinity () const |
| bool | is_minus_infinity () const |
| void | dump (std::ostream &=std::cout) const |
| dump the contents of a vnl_bignum to a stream, default cout. More... | |
Private Member Functions | |
| void | xtoBigNum (const char *s) |
| convert hex string to vnl_bignum. More... | |
| int | dtoBigNum (const char *s) |
| Converts decimal string to a vnl_bignum. More... | |
| void | otoBigNum (const char *s) |
| convert octal string to vnl_bignum. More... | |
| void | exptoBigNum (const char *s) |
| convert exponential string to a vnl_bignum. More... | |
| void | resize (short) |
| change the data allotment for a vnl_bignum. More... | |
| vnl_bignum & | trim () |
| trim non-infinite vnl_bignum of excess data allotment. More... | |
Private Attributes | |
| unsigned short | count |
| int | sign |
| unsigned short * | data |
Friends | |
| int | magnitude_cmp (const vnl_bignum &, const vnl_bignum &) |
| compare absolute values of two vnl_bignums. More... | |
| void | add (const vnl_bignum &, const vnl_bignum &, vnl_bignum &) |
| add two non-infinite vnl_bignum values and save their sum. More... | |
| void | subtract (const vnl_bignum &, const vnl_bignum &, vnl_bignum &) |
| subtract bmin from bmax (unsigned, non-infinite), result in diff. More... | |
| void | increment (vnl_bignum &bnum) |
| Add 1 to bnum (unsigned, non-infinite). More... | |
| void | decrement (vnl_bignum &bnum) |
| Subtract 1 from bnum (unsigned, non-infinite, non-zero). More... | |
| void | multiply_aux (const vnl_bignum &, unsigned short, vnl_bignum &, unsigned short) |
| multiply a non-infinite vnl_bignum by a "single digit". More... | |
| unsigned short | normalize (const vnl_bignum &, const vnl_bignum &, vnl_bignum &, vnl_bignum &) |
| normalize two vnl_bignums. More... | |
| void | divide_aux (const vnl_bignum &, unsigned short, vnl_bignum &, unsigned short &) |
| divide a vnl_bignum by a "single digit". More... | |
| unsigned short | estimate_q_hat (const vnl_bignum &, const vnl_bignum &, unsigned short) |
| estimate next dividend. More... | |
| unsigned short | multiply_subtract (vnl_bignum &, const vnl_bignum &, unsigned short, unsigned short) |
| calculate u - v*q_hat. More... | |
| void | divide (const vnl_bignum &, const vnl_bignum &, vnl_bignum &, vnl_bignum &) |
| 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... | |
| std::ostream & | operator<< (std::ostream &, const vnl_bignum &) |
| Formatted output for bignum. More... | |
| std::istream & | operator>> (std::istream &, vnl_bignum &) |
| Reads a vnl_bignum from a stream. More... | |
| 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. More... | |
| 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. More... | |
Related Functions | |
(Note that these are not member functions.) | |
| void | vsl_b_write (vsl_b_ostream &os, vnl_bignum const &v) |
| Binary save vnl_bignum to stream. More... | |
| void | vsl_b_read (vsl_b_istream &is, vnl_bignum &v) |
| Binary load vnl_bignum from stream. More... | |
| void | vsl_print_summary (std::ostream &os, vnl_bignum const &b) |
| Print human readable summary of object to a stream. More... | |
| vnl_bignum | operator+ (vnl_bignum const &r1, long r2) |
| Returns the sum of two bignum numbers. More... | |
| vnl_bignum | operator- (vnl_bignum const &r1, vnl_bignum const &r2) |
| Returns the difference of two bignum numbers. More... | |
| vnl_bignum | operator * (vnl_bignum const &r1, vnl_bignum const &r2) |
| Returns the product of two bignum numbers. More... | |
| vnl_bignum | operator/ (vnl_bignum const &r1, vnl_bignum const &r2) |
| Returns the division of two bignum numbers. More... | |
| vnl_bignum | operator% (vnl_bignum const &r1, vnl_bignum const &r2) |
| Returns the remainder of r1 divided by r2. More... | |
Infinite precision integers.
The vnl_bignum class implements near-infinite precision integers and arithmetic by using a dynamic bit vector. A vnl_bignum object will grow in size as necessary to hold its integer value. Implicit conversion to the system defined types: short, int, long, float, double and long double is supported by overloaded operator member functions. Addition and subtraction operators are performed by simple bitwise addition and subtraction on unsigned short boundaries with checks for carry flag propagation. The multiplication, division, and remainder operations utilize the algorithms from Knuth's Volume 2 of "The Art of Computer Programming". However, despite the use of these algorithms and inline member functions, arithmetic operations on vnl_bignum objects are considerably slower than the built-in integer types that use hardware integer arithmetic capabilities.
The vnl_bignum class supports the parsing of character string representations of all the literal number formats, PLUS the strings "Infinity", "+Infinity" and "-Infinity". The following table shows an example of a character string representation on the left and a brief description of the interpreted meaning on the right:
Character String Interpreted Meaning 1234 1234 1234l 1234 1234L 1234 1234u 1234 1234U 1234 1234ul 1234 1234UL 1234 01234 1234 in octal (leading 0) 0x1234 1234 in hexadecimal (leading 0x) 0X1234 1234 in hexadecimal (leading 0X) 123.4 123 (value truncated) 1.234e2 123 (exponent expanded/truncated) 1.234e-5 0 (truncated value less than 1) Infinity +Inf ("maxval", obeying all conventional arithmetic)
Definition at line 143 of file vnl_bignum.h.
| vnl_bignum::vnl_bignum | ( | ) |
Creates a zero vnl_bignum.
Definition at line 20 of file vnl_bignum.cxx.
| vnl_bignum::vnl_bignum | ( | long | l | ) |
Creates a vnl_bignum from a long integer.
Definition at line 27 of file vnl_bignum.cxx.
| vnl_bignum::vnl_bignum | ( | unsigned long | l | ) |
Creates a vnl_bignum from an unsigned long integer.
Definition at line 75 of file vnl_bignum.cxx.
| vnl_bignum::vnl_bignum | ( | int | l | ) |
Creates a vnl_bignum from an integer.
Definition at line 51 of file vnl_bignum.cxx.
| vnl_bignum::vnl_bignum | ( | unsigned int | l | ) |
Creates a vnl_bignum from an unsigned integer.
Definition at line 95 of file vnl_bignum.cxx.
| vnl_bignum::vnl_bignum | ( | float | f | ) |
Creates a vnl_bignum from a single-precision floating point number.
Definition at line 115 of file vnl_bignum.cxx.
| vnl_bignum::vnl_bignum | ( | double | d | ) |
Creates a vnl_bignum from a double floating point number.
Definition at line 147 of file vnl_bignum.cxx.
| vnl_bignum::vnl_bignum | ( | long double | d | ) |
Creates a vnl_bignum from a "long double" floating point number.
Definition at line 178 of file vnl_bignum.cxx.
| vnl_bignum::vnl_bignum | ( | vnl_bignum const & | b | ) |
Copies the contents of vnl_bignum b.
Definition at line 384 of file vnl_bignum.cxx.
| vnl_bignum::vnl_bignum | ( | const char * | s | ) |
Creates a vnl_bignum from the character string representation.
Definition at line 326 of file vnl_bignum.cxx.
| vnl_bignum::~vnl_bignum | ( | ) |
Frees space for vnl_bignum.
Definition at line 399 of file vnl_bignum.cxx.
|
inline |
Definition at line 231 of file vnl_bignum.h.
|
private |
Converts decimal string to a vnl_bignum.
Definition at line 771 of file vnl_bignum.cxx.
| void vnl_bignum::dump | ( | std::ostream & | os = std::cout | ) | const |
dump the contents of a vnl_bignum to a stream, default cout.
Definition at line 744 of file vnl_bignum.cxx.
|
private |
convert exponential string to a vnl_bignum.
Definition at line 789 of file vnl_bignum.cxx.
|
inline |
Definition at line 234 of file vnl_bignum.h.
|
inline |
Definition at line 236 of file vnl_bignum.h.
|
inline |
Definition at line 235 of file vnl_bignum.h.
| vnl_bignum & vnl_bignum::operator *= | ( | vnl_bignum const & | r | ) |
Multiplies this with a vnl_bignum.
Definition at line 503 of file vnl_bignum.cxx.
| vnl_bignum::operator double | ( | ) | const |
Implicit conversion from a vnl_bignum to a double.
Definition at line 722 of file vnl_bignum.cxx.
|
inline |
Definition at line 172 of file vnl_bignum.h.
| vnl_bignum::operator float | ( | ) | const |
Implicit conversion from a vnl_bignum to a float.
Definition at line 711 of file vnl_bignum.cxx.
|
inline |
Definition at line 171 of file vnl_bignum.h.
| vnl_bignum::operator int | ( | ) | const |
Implicit conversion from a vnl_bignum to an int.
Definition at line 691 of file vnl_bignum.cxx.
|
inline |
Definition at line 169 of file vnl_bignum.h.
| vnl_bignum::operator long | ( | ) | const |
Implicit conversion from a vnl_bignum to a long.
Definition at line 701 of file vnl_bignum.cxx.
|
inline |
Definition at line 170 of file vnl_bignum.h.
| vnl_bignum::operator long double | ( | ) | const |
Implicit conversion from a vnl_bignum to a long double.
Definition at line 733 of file vnl_bignum.cxx.
|
inline |
Definition at line 173 of file vnl_bignum.h.
| vnl_bignum::operator short | ( | ) | const |
Implicit conversion from a vnl_bignum to a short.
Definition at line 683 of file vnl_bignum.cxx.
|
inline |
Definition at line 168 of file vnl_bignum.h.
|
inline |
Definition at line 202 of file vnl_bignum.h.
|
inline |
Definition at line 207 of file vnl_bignum.h.
|
inline |
Definition at line 213 of file vnl_bignum.h.
|
inline |
Definition at line 219 of file vnl_bignum.h.
|
inline |
Definition at line 225 of file vnl_bignum.h.
| vnl_bignum & vnl_bignum::operator%= | ( | vnl_bignum const & | r | ) |
Divides this by a vnl_bignum and replaces this by remainder.
Definition at line 541 of file vnl_bignum.cxx.
|
inline |
Definition at line 176 of file vnl_bignum.h.
| vnl_bignum vnl_bignum::operator+ | ( | vnl_bignum const & | r | ) | const |
Adds two vnl_bignums, and returns new sum.
Definition at line 474 of file vnl_bignum.cxx.
| vnl_bignum & vnl_bignum::operator++ | ( | ) |
prefix increment (++b).
Prefix increment. Increments a vnl_bignum by 1, and returns it.
Definition at line 436 of file vnl_bignum.cxx.
|
inline |
postfix increment (b++).
Definition at line 196 of file vnl_bignum.h.
|
inline |
Definition at line 183 of file vnl_bignum.h.
| vnl_bignum vnl_bignum::operator- | ( | ) | const |
Returns the negation of a vnl_bignum.
Definition at line 426 of file vnl_bignum.cxx.
| vnl_bignum & vnl_bignum::operator-- | ( | ) |
decrement.
Prefix decrement. Decrements a vnl_bignum by 1, and returns it.
Definition at line 455 of file vnl_bignum.cxx.
|
inline |
decrement.
Definition at line 198 of file vnl_bignum.h.
|
inline |
Definition at line 184 of file vnl_bignum.h.
| vnl_bignum & vnl_bignum::operator/= | ( | vnl_bignum const & | r | ) |
Divides this by a vnl_bignum.
Definition at line 524 of file vnl_bignum.cxx.
| bool vnl_bignum::operator< | ( | vnl_bignum const & | rhs | ) | const |
Compares two vnl_bignums.
Definition at line 605 of file vnl_bignum.cxx.
|
inline |
Definition at line 208 of file vnl_bignum.h.
|
inline |
Definition at line 214 of file vnl_bignum.h.
|
inline |
Definition at line 220 of file vnl_bignum.h.
|
inline |
Definition at line 226 of file vnl_bignum.h.
| vnl_bignum vnl_bignum::operator<< | ( | int | l | ) | const |
Shifts bignum to the left l digits.
Definition at line 557 of file vnl_bignum.cxx.
|
inline |
Definition at line 188 of file vnl_bignum.h.
|
inline |
Definition at line 204 of file vnl_bignum.h.
|
inline |
Definition at line 210 of file vnl_bignum.h.
|
inline |
Definition at line 216 of file vnl_bignum.h.
|
inline |
Definition at line 222 of file vnl_bignum.h.
|
inline |
Definition at line 228 of file vnl_bignum.h.
| vnl_bignum & vnl_bignum::operator= | ( | const vnl_bignum & | rhs | ) |
Copies rhs vnl_bignum to lhs vnl_bignum.
Definition at line 406 of file vnl_bignum.cxx.
| bool vnl_bignum::operator== | ( | vnl_bignum const & | rhs | ) | const |
Two vnl_bignums are equal if and only if they have the same integer representation.
Definition at line 587 of file vnl_bignum.cxx.
|
inline |
Definition at line 206 of file vnl_bignum.h.
|
inline |
Definition at line 212 of file vnl_bignum.h.
|
inline |
Definition at line 218 of file vnl_bignum.h.
|
inline |
Definition at line 224 of file vnl_bignum.h.
|
inline |
Definition at line 203 of file vnl_bignum.h.
|
inline |
Definition at line 209 of file vnl_bignum.h.
|
inline |
Definition at line 215 of file vnl_bignum.h.
|
inline |
Definition at line 221 of file vnl_bignum.h.
|
inline |
Definition at line 227 of file vnl_bignum.h.
|
inline |
Definition at line 205 of file vnl_bignum.h.
|
inline |
Definition at line 211 of file vnl_bignum.h.
|
inline |
Definition at line 217 of file vnl_bignum.h.
|
inline |
Definition at line 223 of file vnl_bignum.h.
|
inline |
Definition at line 229 of file vnl_bignum.h.
| vnl_bignum vnl_bignum::operator>> | ( | int | l | ) | const |
Shifts bignum to the right l digits.
Definition at line 572 of file vnl_bignum.cxx.
|
inline |
Definition at line 189 of file vnl_bignum.h.
|
private |
convert octal string to vnl_bignum.
Definition at line 827 of file vnl_bignum.cxx.
|
private |
change the data allotment for a vnl_bignum.
Definition at line 841 of file vnl_bignum.cxx.
|
private |
trim non-infinite vnl_bignum of excess data allotment.
Definition at line 869 of file vnl_bignum.cxx.
|
private |
convert hex string to vnl_bignum.
Definition at line 813 of file vnl_bignum.cxx.
|
friend |
add two non-infinite vnl_bignum values and save their sum.
Definition at line 887 of file vnl_bignum.cxx.
|
friend |
Subtract 1 from bnum (unsigned, non-infinite, non-zero).
Definition at line 969 of file vnl_bignum.cxx.
|
friend |
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.)
Definition at line 1187 of file vnl_bignum.cxx.
|
friend |
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.)
Definition at line 1062 of file vnl_bignum.cxx.
|
friend |
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.)
Definition at line 1082 of file vnl_bignum.cxx.
|
friend |
Add 1 to bnum (unsigned, non-infinite).
Definition at line 928 of file vnl_bignum.cxx.
|
friend |
left shift (arithmetic) non-infinite vnl_bignum by positive number.
Definition at line 1246 of file vnl_bignum.cxx.
|
friend |
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.
|
friend |
multiply a non-infinite vnl_bignum by a "single digit".
Definition at line 1009 of file vnl_bignum.cxx.
|
friend |
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.)
Definition at line 1129 of file vnl_bignum.cxx.
|
friend |
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.)
Definition at line 1045 of file vnl_bignum.cxx.
|
related |
Returns the product of two bignum numbers.
Definition at line 302 of file vnl_bignum.h.
|
related |
Returns the remainder of r1 divided by r2.
Definition at line 396 of file vnl_bignum.h.
|
related |
Returns the sum of two bignum numbers.
Definition at line 279 of file vnl_bignum.h.
|
related |
Returns the difference of two bignum numbers.
Definition at line 290 of file vnl_bignum.h.
|
related |
Returns the division of two bignum numbers.
Definition at line 349 of file vnl_bignum.h.
|
friend |
|
friend |
|
friend |
right shift (arithmetic) non-infinite vnl_bignum by positive number.
Definition at line 1284 of file vnl_bignum.cxx.
|
friend |
subtract bmin from bmax (unsigned, non-infinite), result in diff.
Definition at line 947 of file vnl_bignum.cxx.
|
friend |
Convert the number from a decimal representation in a string.
Definition at line 667 of file vnl_bignum.cxx.
|
friend |
Convert the number to a decimal representation in a string.
Definition at line 643 of file vnl_bignum.cxx.
|
related |
Binary load vnl_bignum from stream.
Definition at line 21 of file vnl_io_bignum.cxx.
|
related |
Binary save vnl_bignum to stream.
Definition at line 10 of file vnl_io_bignum.cxx.
|
related |
Print human readable summary of object to a stream.
Definition at line 44 of file vnl_io_bignum.cxx.
|
private |
Definition at line 146 of file vnl_bignum.h.
|
private |
Definition at line 148 of file vnl_bignum.h.
|
private |
Definition at line 147 of file vnl_bignum.h.
1.8.15