Adobe Systems Incorporated

cmath Extensions


class  nearest_cast_fn< A, R >


long lround_half_up (double x)
long lround_half_up (float x)
template<typename R , typename A >
nearest_cast (const A &x)
float round_half_up (float x)
double round_half_up (double x)


Compatibility features for C99/TR1 <cmath>.

typedef Float double_t
typedef Float float_t
double round (double x)
float round (float x)
long lround (double x)
long lround (float x)
double trunc (double x)
float trunc (float x)

Detailed Description

<adobe/cmath.hpp> provides type definitions and functions based on the 1999 C Standard header <math.h> wrapped in namespace adobe. Currently, the set of provided types and functions is limited, please request extensions to this file as needed.

The C99/TR1 extensions supplied here for compatibility are:

  • adobe::double_t - A type at least as wide as double.
  • adobe::float_t - A type at least as wide as float.
  • adobe::trunc - Returns the truncated integer value.
  • adobe::round - Returns nearest integer value in floating-point format, rounding halfway cases away from zero, regardless of the current rounding direction.
  • adobe::lround - Same as round(), but returns a long int.

The implementation may #include <math.h>.

There are also additions in this file not related to the C99 but are nevertheless appropriate as cmath extensions.

Typedef Documentation

typedef Float double_t

Definition at line 161 of file cmath.hpp.

typedef Float float_t

Definition at line 162 of file cmath.hpp.

Function Documentation

long adobe::lround ( double  x )
long adobe::lround ( float  x )
long lround_half_up ( double  x )
The nearest integer value, rounding halfway cases towards positive infinity, regardless of the current rounding direction. If the rounded value is outside the range of the return type, the numeric result is unspecified. A range error may occur if the magnitude of x is too large.

Definition at line 192 of file cmath.hpp.

long lround_half_up ( float  x )
adobe::lround_half_up(double x)

Definition at line 195 of file cmath.hpp.

R nearest_cast ( const A &  x )

This function addresses the problem where a value of a floating-point type is to be converted to an unknown user-defined type. If the unknown type is an integral type, the argument should be rounded. If not, the argument should be cast directly to the return type. nearest_cast performs the rounding if necessary using round_half_up().

adobe::nearest_cast_fn is the function object form of adobe::nearest_cast and may be specialized to with a user defined type to customize adobe::nearest_cast.

Type A should be convertible to type R. If R is an integral type, it should be large enough to store the value in x after rounding.
int i = nearest_cast<int>(9.5);
assert(i == 10);

float f = nearest_cast<float>(9.5);
assert(f == 9.5);

template <typename Result, typename Argument> 
Result half(const Argument& x) 
    return nearest_cast<Result>(x/2.0);

template <typename II,  // II models Input Iterator 
          typename OI>  // OI models Output Iterator
void nearest_sequence(II first, II last, OI result)
    std::transform(first, last, result,
        nearest_cast_fn<typename II::value_type, typename OI::value_type>());

Definition at line 210 of file cmath.hpp.

float adobe::round ( float  x )
double adobe::round ( double  x )
double round_half_up ( double  x )
The nearest integer value in floating-point format, rounding halfway cases towards positive infinity, regardless of the current rounding direction.

Definition at line 186 of file cmath.hpp.

float round_half_up ( float  x )
adobe::round_half_up(double x).

Definition at line 189 of file cmath.hpp.

double adobe::trunc ( double  x )
float adobe::trunc ( float  x )

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google