Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Essential Math Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

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 the Essential Math Module: 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 the Essential Math Module. We include an example numeric class, Rational, located in file rational.h in your Rogue Wave examples directory. 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 the Essential Math Module, 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 the Essential Math Module. 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 SourcePro C++ API Reference Guide.

2.2.2.2 Adding Global and Specialized Functions



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.