11 * Convert a string to a fixed-point 32-bit value.
13 * Ignores `locale' stuff.
16 _DEFUN (_strtoufix32_r
, (rptr
, nptr
, endptr
),
17 struct _reent
*rptr _AND
18 _CONST
char *nptr _AND
21 union double_union dbl
;
23 __uint32_t tmp
, tmp2
, result
= 0;
25 dbl
.d
= _strtod_r (rptr
, nptr
, endptr
);
27 /* treat NAN as domain error, +/- infinity as saturation */
35 rptr
->_errno
= ERANGE
;
36 if (word0(dbl
) & Sign_bit
)
41 /* check for normal saturation */
44 rptr
->_errno
= ERANGE
;
49 rptr
->_errno
= ERANGE
;
53 /* otherwise we have normal positive number in range */
55 /* strip off exponent */
56 exp
= ((word0(dbl
) & Exp_mask
) >> Exp_shift
) - Bias
;
60 word0(dbl
) &= ~(Exp_mask
| Sign_bit
);
61 /* add in implicit normalized bit */
62 word0(dbl
) |= Exp_msk1
;
63 /* shift so result is contained left-justified in word */
64 tmp
= word0(dbl
) << Ebits
;
65 tmp
|= ((unsigned long)word1(dbl
) >> (32 - Ebits
));
66 /* perform rounding */
69 tmp2
= tmp
+ (1 << (negexp
- 2));
70 result
= (tmp2
>> (negexp
- 1));
71 /* if rounding causes carry, add carry bit in */
73 result
+= 1 << (32 - negexp
);
77 result
= tmp
+ ((word1(dbl
) & (1 << (32 - Ebits
- 1))) != 0);
78 /* if rounding causes carry, then saturation has occurred */
81 rptr
->_errno
= ERANGE
;
92 _DEFUN (strtoufix32
, (s
, ptr
, base
),
96 return _strtoufix32_r (_REENT
, s
, ptr
);