## ## OSSP ui64 - 64-Bit Arithmetic ## Copyright (c) 2002-2005 Ralf S. Engelschall ## Copyright (c) 2002-2005 The OSSP Project ## ## This file is part of OSSP ui64, a 64-bit arithmetic library ## which can be found at http://www.ossp.org/pkg/lib/ui64/. ## ## Permission to use, copy, modify, and distribute this software for ## any purpose with or without fee is hereby granted, provided that ## the above copyright notice and this permission notice appear in all ## copies. ## ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ## SUCH DAMAGE. ## ## ui64.pod: library manual page ## =pod =head1 NAME B - 64-Bit Arithmetic =head1 VERSION B =head1 SYNOPSIS B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B. =head1 DESCRIPTION B is a small B library for portable 64-bit arithmetic. It allows to perform the usual arithmetical and bit-wise operations on a B type B which resembles a 64-bit unsigned integer type. In contrast to a built-in C type like the C94 B or even the similar C99 B, the operations on B provide full support for correct carry/overflow semantics. The library does no dynamic memory allocations at all and instead passes B objects by value within the API. This provides a very convinient and low-overhead interface. Internally, B stores the B in exactly (the expected) 8 octets which at any time hold the 64-bit value in a portable I<8-digits-to-base-256> representation. Nevertheless the B type should be treated as an opaque type. =head1 APPLICATION PROGRAMMER INTERFACE (API) =head2 Particular Values API functions providing particular values: =over 4 =item ui64_t B(void); The value 0, expressed as an B. =item ui64_t B(void); The maximum value expressable as an B. =back =head2 Import & Export API functions providing value importing and exporting to and from native B representations: =over 4 =item ui64_t B(unsigned long I); Import value from B C I. =item unsigned long B(ui64_t I); Export value of I to B C. This operation is not less-less if the 64-bit value in I exceeds the B value C. =item ui64_t B(const char *I, char **I, int I); Import value from C-terminated B string representation starting at I. The representation can have leading whitespaces and its (case-insensitive) digits (C<0>, ..., C<9>, C, ..., C) are interpreted to base I. I has to be greater or equal 2 and less than 36. If I is not C, it is set to the first character after the imported value representation. =item char *B(ui64_t I, char *I, size_t I, int I); Export value of I to B string representation. The representation consists of digits (C<0>, ..., C<9>, C, ..., C) and form the value to base I. I has to be greater or equal 2 and less than 36. The representation is stored into the buffer starting at I and lasting I bytes. =back =head2 Arithmetical Operations API functions performing the standard arithmetical operations: =over 4 =item ui64_t B(ui64_t I, ui64_t I, ui64_t *I); Addition of I and I. If I is not C, it receives the overflow value of this operation (carry). =item ui64_t B(ui64_t I, int I, int *I); Same as B, but I and I are single digits to base 256. =item ui64_t B(ui64_t I, ui64_t I, ui64_t *I); Subtraction of I from I. If I is not C, it receives the overflow value of this operation (borrow). =item ui64_t B(ui64_t I, int I, int *I); Same as B, but I and I are single digits to base 256. =item ui64_t B(ui64_t I, ui64_t I, ui64_t *I); Multiplication of I and I. If I is not C, it receives the overflow value of this operation). =item ui64_t B(ui64_t I, int I, int *I); Same as B, but I and I are single digits to base 256. =item ui64_t B(ui64_t I, ui64_t I, ui64_t *I); Division of I by I. If I is not C, it receives the overflow value of this operation (remainder). =item ui64_t B(ui64_t I, int I, int *I); Same as B, but I and I are single digits to base 256. =back =head2 Bit Operations API functions performing the standard bit-wise operations: =over 4 =item ui64_t B(ui64_t I, ui64_t I); Bit-wise I operation between I and I. =item ui64_t B(ui64_t I, ui64_t I); Bit-wise I operation between I and I. =item ui64_t B(ui64_t I, ui64_t I); Bit-wise I operation between I and I. =item ui64_t B(ui64_t I); Bit-wise I operation of I. =item ui64_t B(ui64_t I, int I, ui64_t *I); Bit-wise I operation by I bits of I. If I is not C, it contains the out-rotated bits. =item ui64_t B(ui64_t I, int I, ui64_t *I); Bit-wise I operation by I bits of I. If I is not C, it contains the out-rotated bits. =back =head2 Other Operations =over 4 =item int B(ui64_t I); Number of digits (1-8) to base 256 in I. =item int B(ui64_t I, ui64_t I); Comparison of I and I values. Returns C<-1>, C<0> or C<+1> if I is less/equal/greater than I. =back =head1 HISTORY B was invented in April 2002 by I Erse@engelschall.comE for use inside the B project. Its creation was prompted by the requirement to calculate with 64-bit integers inside B, a time calculation library. The core implementation is derived from the B library in I's book I. =head1 AUTHORS Ralf S. Engelschall rse@engelschall.com www.engelschall.com =cut