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

White Paper (pdf):
High precision C++
arithmetic (345 KB)

Number Class Overview
 
Fast, high-precision decimal arithmetic for C++

Base One Number Class - Introduction

  • Full ANSI/C++ source code, with extensive comments and documentation
  • Source is Windows, Unix, and 64-bit ready
  • Support for Windows 2003, XP, 2000
  • STL (Standard Template Library) and MFC (Microsoft Foundation Classes) support
  • Thorough online documentation and examples
  • One-year priority email support
  • Unconditional 30-day money back guarantee

The Base/1 Number Class is an innovative technology for performing extremely precise mathematical calculations. If you are a programmer building applications for a large financial institution, an engineer designing a high-precision telemetry system, or a scientist striving to minimize errors in the analysis of experimental data, you will immediately recognize the value of Base One's Number Class. Even in less demanding applications you may be surprised to discover how often undetected computational errors lead to significant inaccuracies, which are readily eliminated by using our Number Class.

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

 
 

(Doc)  2 + 2 = 5 ???

Mistakes don't have to be this obvious to have equally disastrous consequences.
Here's one you're more likely to run into:

5.5 Mod 1.1 = 1.1 ???

Shouldn't the remainder (modulo 1.1) be 0?
Definitely, since 5.5 is a perfect multiple of 1.1
Check it for yourself using Windows' Calculator or Microsoft's fmod() function on any Windows 95 or early version of NT 4.0 machine. This bug is avoided when you use Base One's Number Class. The modulo bug described above seems to have been fixed in later operating systems and service packs from Microsoft. However, here's a newer one we discovered while testing of the Number Class:
d1 = 8853.41959899;
d2 = 2951.13986633;
fmod( d1, d2 ) returns d2
instead of returning zero!
In this example, d1 is a perfect multiple of d2 (d1 = d2 * 3). We got this error on Windows NT Service Pack 5 and 6a and Windows 2000 server. For some versions, the bug did not appear in the calculator program, but using fmod() always produced this bug. The Number Class properly returns the correct remainder of zero.

Why Use The Base/1 Number Class?

Base One's Number Class is a general-purpose alternative to the built-in numeric data types of C++, with added safeguards against a variety of common (and not-so-common) errors.  Whether you write programs for DOS, Windows, Unix, or any other platform, you can use our Number Class just as easily as the native C++ number types.  If you have an existing application, conversion couldn't be easier.  With a few localized changes to include our header files, huge applications can be made to support greatly enhanced precision simply by recompiling.  You could pay ten times as much for a competitor's product, and still not get the features that set the Base/1 Number Class apart from the rest.

The Unique Advantages of Base One's Number Class

  • uncompromisingly exact decimal arithmetic

  • up to 100 significant digits of precision with the decimal point at any desired digit

  • eliminates pervasive rounding errors and automatically detects overflows

  • efficient arithmetic on both very large and very small numbers

  • blazingly fast comparison logic makes it ideal for searching, sorting, and indexing

  • compact representation minimizes memory and disk storage requirements

  • well suited to database applications, including support of nulls (blanks)

  • fully documented ANSI/C++ source code with an extensive set of examples

  • plus still more benefits when used with the Base/1 Foundation Component Library


A Case in Point  

As one of the world's largest banks, our client was used to dealing with large numbers. With foreign currency conversions, sensitive interest rate calculations, and precise financial reporting requirements, they were continually running into the limitations built into C++. In order to cope with large numbers, they had to sacrifice accuracy, which is definitely frowned upon in their line of business.

When the bank decided to port their application from 16 to 32-bit, they were surprised to discover that Microsoft had actually lowered the maximum precision of floating point numbers from 19 to 16 digits. Add to this the complication of planning for the new Euro currency standard, imposing still further demands on precision, and you can see how they crossed the limits of what could be handled by conventional C++ numeric data types. With C++'s large integer and currency data types, scaling logic made the prospect of dealing with more than 16 digits and more than 4 digits to the right of the decimal point a programming nightmare. They also considered third-party libraries supporting variations of Binary Coded Decimal (BCD) and Packed Decimal. These could represent large numbers, but only at the expense of choosing either grossly inflated storage requirements for fixed length fields, or highly inefficient arithmetic and comparison operations for variable length fields. In addition the reprogramming costs were unacceptable.

We showed them how to solve their problems with our Number Class. They liked it so much that they instituted a department-wide policy mandating use of the Base/1 Number Class throughout all of their applications.

 


"We were astounded to discover how many of our reports showed discrepancies before and after trying out the Base/1 Number Class. We checked the arithmetic and confirmed that Base One's calculations were right."
Vice President, Deutsche Bank


"I was dreading the job of squeezing more precision out of our system for the Euro-awareness project. When I saw how little programming it would take with the Base/1 Number Class, I was ecstatic. We finished the project so far ahead of schedule, my boss gave me an extra 3 days of vacation."
Senior Systems Analyst, Deutsche Bank


(click for more about representation)If you'd like to know more about our unique way of handling numbers, take a look at the page describing the Base/1 Number Class internal representation in detail.

Also see our algorithms page for in-depth descriptions and examples with more diagrams like the one below.

(click for more about algorithms)


Comprehensive Error Handling

Even if your application doesn't require the highest level of precision, Base One's Number Class makes it easier to write reliable applications by adding convenient error-trapping features. This covers errors like Overflow, Divide by zero, Invalid sign, etc., which are not handled automatically by C++.

C++ provides only minimal facilities for detecting and handling errors that can occur in numeric arithmetic and conversion operations. This makes it necessary for programmers to take extra steps to be sure that certain errors, such as division by zero and overflow, can not occur. Otherwise, a program may crash or simply yield incorrect results when one of these exceptional conditions arises.

All too often obscure bugs result from failing to add adequate error checking logic. The Number Class provides additional capabilities for detecting and handling errors, so these details don't burden the programmer but they also don't get overlooked.


Overflow errors

If you add two conventional C++ numbers and the correct result requires more digits than the variable can hold, C++ doesn't detect the error, as you might have expected if you were accustomed to programming on old mainframe computers. Instead, C++ simply wraps the value, effectively truncating the most significant digits and producing totally incorrect results without any notification. Base One's Number Class gives you an easy way to trap and handle these errors, without having to write extra code to explicitly check for overflow on each arithmetic operation.

Division by zero

C++ also doesn't detect invalid attempts to divide a number by zero (unless you consider immediately crashing to be a form of error "detection"). This too is a type of error that the Number Class makes easy to trap and handle cleanly, again without a lot of extra code. The Number Class also detects attempts to raise 0 to a negative power.


Conversion errors  

Another important category of errors is those that can occur when converting back and forth between different types of numeric and character representations. The limited error-handling features of C++'s conversion functions are greatly improved upon in the Base/1 Number Class. For example, Number Class conversions discriminate among many specific error types, such as invalid sign, missing digit, negative number converted to an unsigned data type, particular flavors of overflow, etc. You also have the choice of detecting errors either based on a return code or by raising an exception for which you can supply your own handler.

Bottom line: you are guaranteed to be warned if the number is too large to be stored or if a desired degree of accuracy (precision) can't be maintained. Using the Number Class prevents the silent destructiveness of overflow, which comes with all the C++ numeric data types.

But the main point is that clsNumDbFld numbers can be large - with many digits both to the left and to the right of the decimal point. Support for larger ranges of values avoids insidious arithmetic truncation, without any special effort dedicated to overflow error detection and handling.


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