Boost C++ Libraries Home Libraries People FAQ More

Next

Chapter 1. Boost.NumericConversion

Fernando Luis Cacciola Carballal

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

Table of Contents

Overview
Definitions
Introduction
Types and Values
C++ Arithmetic Types
Numeric Types
Range and Precision
Exact, Correctly Rounded and Out-Of-Range Representations
Standard (numeric) Conversions
Subranged Conversion Direction, Subtype and Supertype
converter<> function object
Synopsis
Template parameters
Member functions
Range Checking Logic
Examples
Type Requirements and User-defined-types support
Type Requirements
UDT's special semantics
Special Policies
bounds<> traits class
Introduction
traits class bounds<N>
Examples
conversion_traits<> traits class
Types
Examples
Numeric Converter Policy Classes
enum range_check_result
Policy OverflowHandler
Policy Float2IntRounder
Policy RawConverter
Policy UserRangeChecker
Improved numeric_cast<>
Introduction
numeric_cast
Examples
History and Acknowledgments
Bibliography

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.

Last revised: November 20, 2009 at 09:59:43 GMT


Next