11 * Convert a string to a fixed-point (sign + 63-bits) value.
13 * Ignores `locale' stuff.
16 _DEFUN (_strtosfix64_r
, (rptr
, nptr
, endptr
),
17 struct _reent
*rptr _AND
18 _CONST
char *nptr _AND
21 union long_double_union ldbl
;
22 int exp
, negexp
, sign
, ld_type
;
28 _simdstrtold ((char *)nptr
, endptr
, &ldbl
);
30 /* treat NAN as domain error, +/- infinity as saturation */
31 ld_type
= _simdldcheck (&ldbl
);
39 rptr
->_errno
= ERANGE
;
40 if (word0(ldbl
) & Sign_bit
)
45 /* strip off sign and exponent */
46 sign
= word0(ldbl
) & Sign_bit
;
47 exp
= ((word0(ldbl
) & Exp_mask
) >> Exp_shift
) - Bias
;
51 word0(ldbl
) &= ~(Exp_mask
| Sign_bit
);
52 /* add in implicit normalized bit */
53 word0(ldbl
) |= Exp_msk1
;
54 /* shift so result is contained in single word */
55 tmp
= word0(ldbl
) << Ebits
;
56 tmp
|= ((unsigned long)word1(ldbl
) >> (32 - Ebits
));
59 tmp
|= ((unsigned long)word1(ldbl
) << Ebits
);
60 tmp
|= ((unsigned long)word2(ldbl
) >> (32 - Ebits
));
62 /* check for saturation */
65 if (exp
> 0 || (exp
== 0 && tmp
!= 0x8000000000000000LL
))
67 rptr
->_errno
= ERANGE
;
75 rptr
->_errno
= ERANGE
;
80 /* otherwise we have normal number in range */
83 /* perform rounding */
84 tmp2
= tmp
+ (1 << (negexp
- 1));
85 result
= (long long)(tmp2
>> negexp
);
86 /* check if rounding caused carry bit which must be added into result */
88 result
|= (1 << (64 - negexp
));
89 /* check if positive saturation has occurred because of rounding */
90 if (!sign
&& result
< 0)
92 rptr
->_errno
= ERANGE
;
98 /* we have -1.0, no rounding necessary */
102 return sign
? -result
: result
;
108 _DEFUN (strtosfix64
, (s
, ptr
, base
),
112 return _strtosfix64_r (_REENT
, s
, ptr
);