11 * Convert a string to a fixed-point 32-bit value.
13 * Ignores `locale' stuff.
16 _strtoufix32_r (struct _reent
*rptr
,
20 union double_union dbl
;
22 __uint32_t tmp
, tmp2
, result
= 0;
24 dbl
.d
= _strtod_r (rptr
, nptr
, endptr
);
26 /* treat NAN as domain error, +/- infinity as saturation */
31 _REENT_ERRNO(rptr
) = EDOM
;
34 _REENT_ERRNO(rptr
) = ERANGE
;
35 if (word0(dbl
) & Sign_bit
)
40 /* check for normal saturation */
43 _REENT_ERRNO(rptr
) = ERANGE
;
48 _REENT_ERRNO(rptr
) = ERANGE
;
52 /* otherwise we have normal positive number in range */
54 /* strip off exponent */
55 exp
= ((word0(dbl
) & Exp_mask
) >> Exp_shift
) - Bias
;
59 word0(dbl
) &= ~(Exp_mask
| Sign_bit
);
60 /* add in implicit normalized bit */
61 word0(dbl
) |= Exp_msk1
;
62 /* shift so result is contained left-justified in word */
63 tmp
= word0(dbl
) << Ebits
;
64 tmp
|= ((unsigned long)word1(dbl
) >> (32 - Ebits
));
65 /* perform rounding */
68 tmp2
= tmp
+ (1 << (negexp
- 2));
69 result
= (tmp2
>> (negexp
- 1));
70 /* if rounding causes carry, add carry bit in */
72 result
+= 1 << (32 - negexp
);
76 result
= tmp
+ ((word1(dbl
) & (1 << (32 - Ebits
- 1))) != 0);
77 /* if rounding causes carry, then saturation has occurred */
80 _REENT_ERRNO(rptr
) = ERANGE
;
91 strtoufix32 (const char *s
,
94 return _strtoufix32_r (_REENT
, s
, ptr
);