(Base One logo) .NET database and distributed computing tools

Base One Number Class
Internal Representation

The Base One Number Class - Overview

(U.S. Patent Number 6,384,748)


(click to zoom)Base One's Number Class uses a proprietary internal representation to support arithmetic on very large numbers and exact fractions of up to 100 decimal digits. This design makes it possible to store high precision numbers compactly without sacrificing computational efficiency.

The Number Class is markedly different from conventional fixed or floating point binary numbers, which are inherently limited in their ability to represent exact decimal fractions. While resembling the "packed decimal" of mainframe computers, the Number Class uses a radically different encoding scheme to support much more efficient arithmetic and comparison algorithms. A unique benefit of Base One's encoding is that it makes numbers directly collatable as variable-length byte strings, regardless of the mix of numeric sign, scale, or precision.  Thus the Base/1 Number Class exceptionally well-suited to searching, sorting, and indexing applications.


Examples

The following examples illustrate how some specific numbers are stored in the Base/1 Number Class encoding scheme. These four simple cases cover all the possible combinations of sign on the mantissa and sign on the exponent, i.e. positive and negative numbers, fractions and whole numbers.

In performing the encoding, the first step always is to canonicalize the number into an equivalent form that has a mantissa with a single non-zero digit the the left of the decimal point. Digits are then processed in a pair-wise fashion to pack them into each byte, with the addition of a single trailing zero if needed to fill the last byte. Sign reversals are performed in such a way as to guarantee the collatability of signed numbers and fractions. Finally, a bias of plus or minus 10 adjusts the byte values to assure that a null byte can never occur in either the exponent or the mantissa.

(click to zoom)

(click to zoom)

(click to zoom)

(click to zoom)

Note that this is a variable-length representation allowing numbers to be manipulated as raw null-terminated character strings, which are supported very efficiently in C++. As the precision (length) of  numbers is increased, the fixed overhead of the sign, exponent, and terminator bytes diminishes in importance, and the size approaches 2 decimal digits per byte. Also note the following compact special cases:
  • the Null number is the null string, i.e. a single null byte.
  • Zero is represented by the character string 'o', i.e. the letter between 'n' and 'p' followed by a null termination byte.

Collatability - for efficient indexing and sorting

The following table illustrates how Number Class values collate directly into proper numerical sequence, as conventional C signed character arrays.

Unlike other numeric representations, the Number Class handles variable sign, precision, and scale, as well as a "Null" value with no need for conversion into a different representation for efficient sorting and indexing. Notice how the 10 sample numbers in the table collate correctly, from smallest to largest (null, -123.456, -12.3, -0.439, -0.0123, 0, 0.0123, 0.439, 1.234, and finally 123.456).
Number Internal Representation
as a Null-Terminated String
(Byte Array Values)
1 2 3 4 5 6

(Null)

0          

-123.456

'n' -12 -22 -44 -66 0

-12.3

'n' -11 -22 -40 0  

-0.439

'n' 11 -53 -100 0  
-0.0123 'n' 12 -22 -40 0  
0 'o' 0        
0.0123 'p' -12 22 40 0  
0.439 'p' -11 53 100 0  
1.234 'p' 10 22 44 0  
123.456 'p' 12 22 44 66 0

Number Class Intro | Overview | FAQ | Representation | Algorithms | Sample Usage | Prices


Home Products Consulting Case Studies Order Contents Contact About Us

Copyright 2012, Base One International Corporation