C What does the first of these functions do Left bit shift
C++
What does the first of these functions do?
//: Left \"bit\" shift operator (actually: digit shift, or exponent translation)
inline vnl_decnum operator<<(long int r) const { return sign_==\' \' ? *this : vnl_decnum(sign_, data_, exp_+r); }
inline vnl_decnum operator<<(int r) const { return operator<<((long int)r); }
//: Right \"bit\" shift operator (actually: digit shift, or exponent translation)
inline vnl_decnum operator>>(long int r) const { return sign_==\' \' ? *this : vnl_decnum(sign_, data_, exp_-r); }
inline vnl_decnum operator>>(int r) const { return operator>>((long int)r); }
//: Left \"bit\" shift operator (actually: digit shift, or exponent translation)
inline vnl_decnum& operator<<=(long int r) { if (sign_!=\' \') exp_ += r; return *this; }
inline vnl_decnum& operator<<=(int r) { if (sign_!=\' \') exp_ += r; return *this; }
//: Right \"bit\" shift operator (actually: digit shift, or exponent translation)
inline vnl_decnum& operator>>=(long int r) { if (sign_!=\' \') exp_ -= r; return *this; }
inline vnl_decnum& operator>>=(int r) { if (sign_!=\' \') exp_ -= r; return *this; }
Solution
file
\\brief Infinite precision numbers with decimal arithmetic
The vnl_decnum class implements infinite precision integers and
floating point numbers, with all necessary arithmetic, by using a
dynamically allocated string of decimals for the mantissa.
Implicit conversion to the system defined types short, int, and long
is supported by overloaded operator member functions and explicit
conversions from these types is available through constructors;
additionally, an implicit \"double\" constructor is available (mainly
for use with vnl_decnum_traits), without any guarantees.
Addition and subtraction operators are performed by simple decimal
arithmetic with checks for carry flag propagation.
The multiplication, division, and remainder operations utilize the
naive, commonly known decimal algorithms. Beware that these could be
considerably slower than both the operations on built-in integer
types and those implemented in the class vnl_bignum.
On the other hand, the I/O could be faster since no decimal <==> binary
conversion needs to be performed.
Rounding errors due to imprecise internal representation can never be
made with vnl_decnum, so consider using this class if decimal I/O and
precise arithmetic are crucial.
Since the internal representation is decimal, there is no overhead
for converting between a vnl_decnum and a decimal character string
representation. Hence, there is a constructor from std::string, there
are both << and >> operators, and a cast method to std::string, all
of them essentially no-ops.
Decimal point notation is only supported on input; internally,
only the scientific notation (mantissa and exponent) is used, with
integer mantissa (and, on output, without \"e exponent\" for integers).
Beware that, even for non-integers, the division and modulo operators
are logically speaking integer operations on the mantissa.
E.g., the result of 42e-3 / 30e-4 is 1e1, while 42e-3 / 3e-3 has as
outcome 14, even though numerically 30e-4 == 3e-3.
But then also 42e-3 % 30e-4 returns 12e-3 while 42e-3 % 3e-3 returns 0.
Both results are compatible with
(a/b) * b + (a%b) = a
which is generally true for other integral types as well.
The difference between using e.g. 1000 and 10e2 is essentially similar to
the use of the \"P\" format in Cobol: in the former case, a precision of
four digits is kept, while in the latter only two digits are present (with
two zeros implicitly there). Arithmetic is done with the available precision
only, which explains the outcomes of operator/ and operator%. A similar
logic holds for the difference between e.g. 1000e-2 and 10.
When none of the used vnl_decnum constructor values have an \"e\" (or when
all constructors that you use in your program are on integers), no \"e\" is
ever introduced (except when explicitly using the method compactify()).
In that case, vnl_decnum really behaves as an integral type,
very similar to vnl_bignum, and as an extension of int and long.
In addition to (arbitrary precision) numbers, vnl_decnum also represents
+Infinity, -Infinity, and Nan. Their internal representations are:
(sign,data,exp) = (\'+\',\'Inf\',0L), (\'-\',\'Inf\',0L\'), and (\' \',\'NaN\',0L).
Arithmetic with these entities is as expected: e.g. 1/0=+Inf, 1/Inf=0,
-Inf < n < +Inf, 1+Inf=+Inf, 0/0=NaN, NaN op n = NaN.

