Boost Numeric Conversion Library - Index

###  | # Boost Numeric Conversion Library
--- | ---

This Document Overview History and Acknowledgments Bibliography | Other Documents Definitions `converter<>` function object Type Requirements and User-defined-types support `bounds<>` traits class `conversion_traits<>` traits class Numeric Converter Policy Classes Improved numeric_cast<>

## Overview

The Boost Numeric Conversion library is a collection of tools to describe and perform conversions between values of different numeric types.

The library includes a special alternative for a subset of `std::numeric_limits<>`, the `bounds<>` traits class, which provides a consistent way to obtain the boundary values for the range of a numeric type.

It also includes a set of trait classes which describes the compile-time properties of a conversion from a source to a target numeric type. Both arithmetic and user-defined numeric types can be used.

A policy-based converter object which uses `conversion_traits` to select an optimized implementation is supplied. Such implementation uses an optimal range checking code suitable for the source/target combination.
The converter's out-of-range behavior can be customized via an OverflowHandler policy.
For floating-point to integral conversions, the rounding mode can be selected via the Float2IntRounder policy.
A custom low-level conversion routine (for UDTs for instance) can be passed via a RawConverter policy.
The optimized automatic range-checking logic can be overridden via a UserRangeChecker policy.

## History and Acknowledgments

Pre-formal review:

> Kevlin Henney, with help from David Abrahams and Beman Dawes, originally contributed the previous version of numeric_cast<> which already presented the idea of a runtime range check.
> Later, Eric Ford, Kevin Lynch and the author spotted some genericity problems with that numeric_cast<> which prevented it from being used in a generic layer of math functions.
> An improved numeric_cast<> which properly handled all combinations of arithmetic types was presented.
> David Abrahams and Beman Dawes acknowledged the need of an improved version of numeric_cast<> and supported the submission as originally laid out. Daryl Walker and Darin Adler made some important comments and proposed fixes to the original submission.

> Special thanks go to Björn Karlsoon who helped the author considerably. Having found the problems with numeric_cast<> himself, he revised very carefully the original submission and spot a subtle bug in the range checking implementation. He also wrote part of this documentation and proof-read and corrected other parts. And most importantly: the features now presented here in this library evolved from the original submission as a result of the useful private communications between Björn and the author.

Post-formal review:

Guillaume Melquiond spoted some documentation and code issues, particularly about rounding conversions.
The following people contributed an important review of the design, documentation and code: Kevin Lynch, Thorsten Ottosen, Paul Bristow, Daryle Walker, Jhon Torjo, Eric Ford, Gennadiy Rozental.

## Bibliography

- Standard Documents:
  1. ISO/IEC 14882:98 (C++98 Standard)
  2. ISO/IEC 9899:1999 (C99 Standard)
  3. ISO/IEC 10967-1 (Language Independent Arithmetic (LIA), Part I, 1994)
  4. ISO/IEC 2382-1:1993 (Information Technology - Vocabulary - Part I: Fundamental Terms)
  5. ANSI/IEEE 754-1985 [and IEC 60559:1989] (Binary floating-point)
  6. ANSI/IEEE 854-1988 (Radix Independent floating-point)
  7. ANSI X3/TR-1-82 (Dictionary for Information Processing Systems)
  8. ISO/IEC JTC1/SC22/WG14/N753 C9X Revision Proposal: LIA-1 Binding: Rationale
- Papers:
  1. David Goldberg What Every Computer Scientist Should Know About Floating-Point Arithmetic
  2. Prof. William Kahan papers on floating-point.

Revised 23 June 2004

© Copyright Fernando Luis Cacciola Carballal, 2004

Use, modification, and distribution are subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at www.boost.org/LICENSE_1_0.txt)