decconv(3C)
NAME
decconv, _s2dec, _d2dec, _dec2s, _dec2d − convert between binary and decimal values
SYNOPSIS
#include <ieeefp.h>
void _s2dec(float ∗x, decimal ∗d, int p);
void _d2dec(double ∗x, decimal ∗d, int p);
void _dec2s(decimal ∗d, float ∗x, int p);
void _dec2d(decimal ∗d, double ∗x, int p);
DESCRIPTION
The _s2dec() function returns a decimal floating-point value, given a pointer to a single-precision binary floating-point number and a precision specification.
On input, the value of the ilen field in the decimal should be set to tell how many decimal digits should be output in the mantissa for rounding purposes. If the ilen field is not in the range1 ≤~ilen~≤~9 , a NaN is returned. If the input binary value x is a NaN or infinity, the returned decimal d will be a NaN or infinity with the appropriate sign. The exponential component of the returned decimal value is always two digits. The structure decimal is defined in the <ieeefp.h> header.
The parameterp (0 ≤~p~≤~ilen ) specifies how many of the digits in the output decimal mantissa string are to be considered to be to the right of the implicit decimal point. If p is out of range, a NaN is returned.
The _d2dec() function works like the _s2dec() function except that it takes a pointer to a double-precision value for x. The ilen field must be in the range of1 ≤~ilen~≤~17 , and the exponential component of the returned decimal will contain three digits.
The _dec2s() function returns a single-precision binary floating-point value, given a decimal value and a precision specification.
The parameterp (0 ≤~p~≤~ilen ) tells how many of the digits in the mantissa string are to be considered to be to the right of an implicit decimal point.
Because the decimal format can represent a larger range of numbers than the binary formats, this conversion may overflow or underflow. Upon overflow or underflow, a signed infinity (signed zero) is returned, and the appropriate sticky bit is set.
The mantissa and exponent strings may contain leading zero characters. But, once all leading 0 characters are removed, the mantissa string should have a length>0 and≤ 9 . The exponent string should have a length>0 and≤ 2 . The special case ofd ==~0 (decimal) is detected, in which case the trailing 0 characters in the string are not removed.
The _dec2d() function is analogous to the _dec2s() function except that it returns a double-precision value. After leading 0 characters are removed, the mantissa string should contain no more than 17 digits and the exponent string should contain no more than three digits.
Rounding is performed according to the current rounding mode. The default is round-to-nearest.
Calling these functions may result in the following exceptions: overflow, underflow, inexact result, invalid operation.
SEE ALSO
ANSI C Programmer’s Guide
SunOS 5.1/x86 — Last change: 13 Jul 1990