11 * Convert a string to a fixed-point (sign + 63-bits) value.
13 * Ignores `locale' stuff.
16 _strtosfix64_r (struct _reent
*rptr
,
20 union long_double_union ldbl
;
21 int exp
, negexp
, sign
, ld_type
;
27 _simdstrtold ((char *)nptr
, endptr
, &ldbl
);
29 /* treat NAN as domain error, +/- infinity as saturation */
30 ld_type
= _simdldcheck (&ldbl
);
35 _REENT_ERRNO(rptr
) = EDOM
;
38 _REENT_ERRNO(rptr
) = ERANGE
;
39 if (word0(ldbl
) & Sign_bit
)
44 /* strip off sign and exponent */
45 sign
= word0(ldbl
) & Sign_bit
;
46 exp
= ((word0(ldbl
) & Exp_mask
) >> Exp_shift
) - Bias
;
50 word0(ldbl
) &= ~(Exp_mask
| Sign_bit
);
51 /* add in implicit normalized bit */
52 word0(ldbl
) |= Exp_msk1
;
53 /* shift so result is contained in single word */
54 tmp
= word0(ldbl
) << Ebits
;
55 tmp
|= ((unsigned long)word1(ldbl
) >> (32 - Ebits
));
58 tmp
|= ((unsigned long)word1(ldbl
) << Ebits
);
59 tmp
|= ((unsigned long)word2(ldbl
) >> (32 - Ebits
));
61 /* check for saturation */
64 if (exp
> 0 || (exp
== 0 && tmp
!= 0x8000000000000000LL
))
66 _REENT_ERRNO(rptr
) = ERANGE
;
74 _REENT_ERRNO(rptr
) = ERANGE
;
79 /* otherwise we have normal number in range */
82 /* perform rounding */
83 tmp2
= tmp
+ (1 << (negexp
- 1));
84 result
= (long long)(tmp2
>> negexp
);
85 /* check if rounding caused carry bit which must be added into result */
87 result
|= (1 << (64 - negexp
));
88 /* check if positive saturation has occurred because of rounding */
89 if (!sign
&& result
< 0)
91 _REENT_ERRNO(rptr
) = ERANGE
;
97 /* we have -1.0, no rounding necessary */
101 return sign
? -result
: result
;
107 strtosfix64 (const char *s
,
110 return _strtosfix64_r (_REENT
, s
, ptr
);