![]() |
.NET database and distributed computing tools |
White Paper (pdf): |
|
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
|
||
|
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.
|
|
![]() Also see our algorithms page for in-depth descriptions and examples with more diagrams like the one below. |
|
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 |