1floating_to_decimal(3C) Standard C Library Functions floating_to_decimal(3C)
2
3
4
6 floating_to_decimal, single_to_decimal, double_to_decimal,
7 extended_to_decimal, quadruple_to_decimal - convert floating-point
8 value to decimal record
9
11 #include <floatingpoint.h>
12
13 void single_to_decimal(single *px, decimal_mode *pm,
14 decimal_record *pd, fp_exception_field_type *ps);
15
16
17 void double_to_decimal(double *px, decimal_mode *pm,
18 decimal_record *pd, fp_exception_field_type *ps);
19
20
21 void extended_to_decimal(extended *px, decimal_mode *pm,
22 decimal_record *pd, fp_exception_field_type *ps);
23
24
25 void quadruple_to_decimal(quadruple *px, decimal_mode *pm,
26 decimal_record *pd, fp_exception_field_type *ps);
27
28
30 The floating_to_decimal functions convert the floating-point value at
31 *px into a decimal record at *pd, observing the modes specified in *pm
32 and setting exceptions in *ps. If there are no IEEE exceptions, *ps
33 will be zero.
34
35
36 If *px is zero, infinity, or NaN, then only pd→sign and pd→fpclass are
37 set. Otherwise pd→exponent and pd→ds are also set so that
38
39 (sig)*(pd->ds)*10**(pd->exponent)
40
41
42
43 is a correctly rounded approximation to *px, where sig is +1 or −1,
44 depending upon whether pd→sign is 0 or −1. pd→ds has at least one and
45 no more than DECIMAL_STRING_LENGTH-1 significant digits because one
46 character is used to terminate the string with a null.
47
48
49 pd→ds is correctly rounded according to the IEEE rounding modes in
50 pm→rd. *ps has fp_inexact set if the result was inexact, and has
51 fp_overflow set if the string result does not fit in pd→ds because of
52 the limitation DECIMAL_STRING_LENGTH.
53
54
55 If pm→df == floating_form, then pd→ds always contains pm→ndigits sig‐
56 nificant digits. Thus if *px == 12.34 and pm→ndigits == 8, then pd→ds
57 will contain 12340000 and pd→exponent will contain −6.
58
59
60 If pm→df == fixed_form and pm→ndigits >= 0, then the decimal value is
61 rounded at pm→ndigits digits to the right of the decimal point. For
62 example, if *px == 12.34 and pm→ndigits == 1, then pd→ds will contain
63 123 and pd→exponent will be set to −1.
64
65
66 If pm→df == fixed_form and pm→ndigits< 0, then the decimal value is
67 rounded at −pm→ndigits digits to the left of the decimal point, and
68 pd→ds is padded with trailing zeros up to the decimal point. For exam‐
69 ple, if *px == 12.34 and pm→n digits == −1, then pd→ds will contain 10
70 and pd→exponent will be set to 0.
71
72
73 When pm→df == fixed_form and the value to be converted is large enough
74 that the resulting string would contain more than DECI‐
75 MAL_STRING_LENGTH−1 digits, then the string placed in pd→ds is limited
76 to exactly DECIMAL_STRING_LENGTH-1 digits (by moving the place at which
77 the value is rounded further left if need be), pd→exponent is adjusted
78 accordingly and the overflow flag is set in *ps.
79
80
81 pd->more is not used.
82
83
84 The econvert(3C), fconvert(3C), gconvert(3C), printf(3C), and
85 sprintf(3C) functions all use double_to_decimal().
86
88 See attributes(5) for descriptions of the following attributes:
89
90
91
92
93 ┌─────────────────────────────┬─────────────────────────────┐
94 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
95 ├─────────────────────────────┼─────────────────────────────┤
96 │MT-Level │MT-Safe │
97 └─────────────────────────────┴─────────────────────────────┘
98
100 econvert(3C), fconvert(3C), gconvert(3C), printf(3C), sprintf(3C),
101 attributes(5)
102
103
104
105SunOS 5.11 7 Jun 2005 floating_to_decimal(3C)