ocmath_round_range

 

Description

Round a set of min, max and increment values. The range is defined by pMin and pMax, divide the given range, round the increment and the range [pMin, pMax].

Syntax

int ocmath_round_range( double * pMin, double * pMax, double * pInc, int nSteps = 8 )

Parameters

pMin
[modify] pointer to the min value
pMax
[modify] pointer to the max value
pInc
[modify] pointer the the increment value
nSteps
[input] number of steps to divide the given range roughly defined by pmin and pmax.
If you know the increment and do not want it to be changed, pass 0 for steps.
Its default value is 0.

Return

If this function success, the return value is the number of steps determined after the rounding;

otherwise a negative error code will be returned.

Examples

EX1

void ocmath_round_range_ex1()
{
    double x1 = -23.4;
    double x2 = 235.89;
    double xinc = 9.9;
    int nSteps = ocmath_round_range(&x1, &x2, &xinc, 8);
    printf("After rounding, the result is %d divisions, from %f to %f with an increment of %f\n", nSteps, x1, x2, xinc);
}
// Output of example:
// After rounding, the result is 27 divisions, from -30.000000 to 240.000000 with an increment of 10.000000

Remark

See Also

ocmath_round_with_tolerance

header to Include

origin.h

Reference