Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

2.2 Nonstandard Numeric Types

An important advantage of using templates for collection classes is flexibility. Templates let you create vectors, matrices, and arrays of arbitrary built-in types, and even types you define yourself. For example, you can create a matrix RWGenMat<long double> for doing high-precision floating point calculations, or an array RWMathArray<unsigned short int> for small integers. This flexibility gives you greater control of both accuracy and storage demands for a given application.

Unfortunately, not all compilers conform to the proposed template standards. For this reason, parts of the library are able to support only the six defined types available in earlier versions of Math.h++: DComplex, double, float, int, UChar, and SChar. You can access the full functionality of the library with other numeric types by making a minor change in a library header file, and adding some global functions for the additional numeric types. We will show you how to do this in Section 2.2.2, "Adding New Numeric Types," but let us first discuss the requirements for defining a new numeric type.

2.2.1 Defining a New Numeric Type

If you create an entirely new numeric type not available from your compiler, your numeric class must meet minimum requirements to have full functionality in Math.h++. We include an example numeric class, Rational, located in file rational.h in your Rogue Wave examples directory (see Section 1.4.1 for the location). You can examine this file and use it as a framework for building your own numeric type.

To meet the minimum requirements for full functionality in Math.h++, a numeric type Num must:

In addition, there may be other requirements for a numeric type, depending on your application. These requirements apply only when a type is used in a particular part of the library. For example, the numeric type Num may also be required to:

2.2.2 Adding New Numeric Types

Types other than DComplex, double, float, int, UChar, and SChar are not fully implemented in Math.h++. As mentioned in Section 2.2, "Nonstandard Numeric Types," you must do two things to achieve their full functionality:

Note that most operations work without these additional instructions. However, some portions of the library are unavailable, resulting in compiler errors if you try to access them. Should these problems occur, follow the instructions below. They are only necessary for the portions of the library that you need.

2.2.2.1 Modifying the Numeric Trait Information

As noted in the previous section, you can include a specialization of the template class rw_numeric_traits in a header file containing the declaration of the new type. For built-in types, you have two choices:

Details about the typedefs in rw_numeric_traits are described in the Class Reference.

2.2.2.2 Adding Global and Specialized Functions


Previous fileTop of DocumentContentsIndexNext file

©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.