3 <<strtoufix16>>, <<strtoufix32>>, <<strtoufix64>>---string to signed fixed point
20 __uint16_t strtoufix16 (const char *<[s]>, char **<[ptr]>);
22 __uint32_t strtoufix32 (const char *<[s]>, char **<[ptr]>);
24 __uint64_t strtoufix64 (const char *<[s]>, char **<[ptr]>);
26 __uint16_t _strtoufix16_r (void *<[reent]>,
27 const char *<[s]>, char **<[ptr]>);
29 __uint32_t _strtoufix32_r (void *<[reent]>,
30 const char *<[s]>, char **<[ptr]>);
32 __uint64_t _strtoufix64_r (void *<[reent]>,
33 const char *<[s]>, char **<[ptr]>);
37 __uint16_t strtoufix16 (<[s]>, <[ptr]>)
41 __uint32_t strtoufix32 (<[s]>, <[ptr]>)
45 __uint64_t strtoufix64 (<[s]>, <[ptr]>)
49 __uint16_t _strtoufix16_r (<[reent]>, <[s]>, <[ptr]>)
54 __uint32_t _strtoufix32_r (<[reent]>, <[s]>, <[ptr]>)
59 __uint64_t _strtoufix64_r (<[reent]>, <[s]>, <[ptr]>)
65 The function <<strtoufix16>> converts the string <<*<[s]>>> to
66 a fixed-point 16-bits fraction representation. The function
67 follows the same rules as <<strtod>>.
69 The substring converted is the longest initial
70 subsequence of <[s]>, beginning with the first
71 non-whitespace character, that has the format:
72 .[+|-]<[digits]>[.][<[digits]>][(e|E)[+|-]<[digits]>]
73 The substring contains no characters if <[s]> is empty, consists
74 entirely of whitespace, or if the first non-whitespace
75 character is something other than <<+>>, <<->>, <<.>>, or a
76 digit. If the substring is empty, no conversion is done, and
77 the value of <[s]> is stored in <<*<[ptr]>>>. Otherwise,
78 the substring is converted, and a pointer to the final string
79 (which will contain at least the terminating null character of
80 <[s]>) is stored in <<*<[ptr]>>>. If you want no
81 assignment to <<*<[ptr]>>>, pass a null pointer as <[ptr]>.
83 <<strtoufix32>> is identical to <<strtoufix16>> except that it
84 converts to fixed-point 32-bit fraction representation.
85 <<strtoufix64>> is also similar, except that it converts
86 to fixed-point 64-bit fraction.
88 The alternate functions <<_strtoufix16_r>>, <<_strtoufix32_r>>,
89 and <<_strtoufix64_r>> are reentrant versions.
90 The extra argument <[reent]> is a pointer to a reentrancy structure.
93 The functions return the converted substring value, if any. If
94 no conversion can be performed, then 0 is returned. If the converted
95 value is a NaN, 0 is returned and errno is set to <<EDOM>>.
96 If the converted value exceeds the maximum positive unsigned fixed-point value,
97 the output value is saturated to the maximum value and <<ERANGE>> is stored in
98 errno. If the converted value is less than 0, then the output is saturated to 0
99 and <<ERANGE>> is stored in errno. Otherwise, the converted value is returned in the
100 specified fixed-point format.
103 <<strtoufix16>>, <<strtoufix32>>, and <<strtoufix64>> are non-standard.
105 The OS subroutines of <<strtod>> are required.
115 #include "vfieeefp.h"
118 * Convert a string to a fixed-point 16-bit value.
120 * Ignores `locale' stuff.
123 _DEFUN (_strtoufix16_r
, (rptr
, nptr
, endptr
),
124 struct _reent
*rptr _AND
125 _CONST
char *nptr _AND
128 union double_union dbl
;
129 unsigned long tmp
, tmp2
, result
;
132 dbl
.d
= _strtod_r (rptr
, nptr
, endptr
);
134 /* treat NAN as domain error, +/- infinity as saturation */
142 rptr
->_errno
= ERANGE
;
143 if (word0(dbl
) & Sign_bit
)
148 /* check for normal saturation */
151 rptr
->_errno
= ERANGE
;
156 rptr
->_errno
= ERANGE
;
160 /* otherwise we have normal postive number in range */
162 /* strip off exponent */
163 exp
= ((word0(dbl
) & Exp_mask
) >> Exp_shift
) - Bias
;
167 /* add in implicit normalized bit */
168 tmp
= word0(dbl
) | Exp_msk1
;
169 /* remove exponent and sign */
171 /* perform rounding */
172 tmp2
= tmp
+ (1 << (negexp
+ 14));
173 result
= tmp2
>> (negexp
+ 15);
174 /* if rounding causes carry, must add carry bit in */
179 /* we have overflow which means saturation */
180 rptr
->_errno
= ERANGE
;
183 result
|= (1 << (16 - negexp
));
186 return (__uint16_t
)result
;
192 _DEFUN (strtoufix16
, (s
, ptr
, base
),
196 return _strtoufix16_r (_REENT
, s
, ptr
);