11 * Convert a string to a fixed-point 64-bit unsigned value.
13 * Ignores `locale' stuff.
16 _strtoufix64_r (struct _reent
*rptr
,
20 union long_double_union ldbl
;
21 int exp
, sign
, negexp
, ld_type
;
22 __uint64_t tmp
, tmp2
, result
= 0;
26 _simdstrtold ((char *)nptr
, endptr
, &ldbl
);
28 /* treat NAN as domain error, +/- infinity as saturation */
29 ld_type
= _simdldcheck (&ldbl
);
34 _REENT_ERRNO(rptr
) = EDOM
;
37 _REENT_ERRNO(rptr
) = ERANGE
;
38 if (word0(ldbl
) & Sign_bit
)
40 return ULONG_LONG_MAX
;
43 /* strip off sign and exponent */
44 sign
= word0(ldbl
) & Sign_bit
;
45 exp
= ((word0(ldbl
) & Exp_mask
) >> Exp_shift
) - Bias
;
49 word0(ldbl
) &= ~(Exp_mask
| Sign_bit
);
50 /* add in implicit normalized bit */
51 word0(ldbl
) |= Exp_msk1
;
52 /* shift so result is contained in single word */
53 tmp
= word0(ldbl
) << Ebits
;
54 tmp
|= ((unsigned long)word1(ldbl
) >> (32 - Ebits
));
57 tmp
|= ((unsigned long)word1(ldbl
) << Ebits
);
58 tmp
|= ((unsigned long)word2(ldbl
) >> (32 - Ebits
));
60 /* check for saturation */
63 _REENT_ERRNO(rptr
) = ERANGE
;
68 if (exp
> 0 || (exp
== 0 && tmp
>= 0x8000000000000000LL
))
70 _REENT_ERRNO(rptr
) = ERANGE
;
71 return ULONG_LONG_MAX
;
75 /* otherwise we have normal number in range */
78 tmp2
= tmp
+ (1 << (negexp
- 2));
79 result
= (tmp2
>> (negexp
- 1));
80 /* if rounding causes carry, add carry bit in */
82 result
+= 1 << (64 - negexp
);
88 result
= tmp
+ ((word2(ldbl
) & (1 << (32 - Ebits
- 1))) != 0);
89 /* if rounding causes carry, then saturation has occurred */
92 _REENT_ERRNO(rptr
) = ERANGE
;
93 return ULONG_LONG_MAX
;
106 strtoufix64 (const char *s
,
109 return _strtoufix64_r (_REENT
, s
, ptr
);