@@ -64,16 +64,6 @@ uint64_t _dtoull_c(long double x) {
64
64
}
65
65
#endif
66
66
67
- /**
68
- * @brief set to 0 or 1
69
- * If set to 1, values that truncate to `INT32_MIN`/`INT64_MIN` will be
70
- * handled correctly.
71
- * If set to 0, it can save a little bit of space by removing a comparison from
72
- * `_dtol_c` and `_dtoll_c`. However this will cause values that would truncate
73
- * to `INT32_MIN`/`INT64_MIN` to have an undefined result.
74
- */
75
- #define HANDLE_INT_MIN 1
76
-
77
67
typedef struct f64_sign {
78
68
long double flt ;
79
69
bool sign ;
@@ -106,41 +96,18 @@ static uint64_t f64_to_unsigned(F64_pun val) {
106
96
return val .bin ;
107
97
}
108
98
109
- uint64_t _dtoull_c (long double x ) {
110
- F64_pun val ;
111
- val .flt = x ;
112
- /* overflow || signbit(x) || isinf(x) || isnan(x) */
113
- if (val .reg .BC >= ((Float64_bias + Float64_u64_max_exp ) << Float64_exp_BC_shift )) {
114
- /* undefined return value for negative/overflow/inf/NaN of x */
115
- return 0 ;
116
- }
117
- return f64_to_unsigned (val );
118
- }
119
-
120
- uint32_t _dtoul_c (long double x ) {
121
- F64_pun val ;
122
- val .flt = x ;
123
- /* overflow || signbit(x) || isinf(x) || isnan(x) */
124
- if (val .reg .BC >= ((Float64_bias + Float64_u32_max_exp ) << Float64_exp_BC_shift )) {
125
- /* undefined return value for negative/overflow/inf/NaN values of x */
126
- return 0 ;
127
- }
128
- return (uint32_t )f64_to_unsigned (val );
129
- }
130
-
99
+ /**
100
+ * @brief the exact same routine is used for (long long)long double and
101
+ * (unsigned long long)long double. If the input long double is out of range,
102
+ * then the conversion is UB anyways.
103
+ */
131
104
int64_t _dtoll_c (f64_sign arg ) {
132
105
F64_pun val ;
133
106
bool x_sign = arg .sign ;
134
107
val .flt = arg .flt ;
135
108
136
109
/* overflow || isinf(x) || isnan(x) */
137
- if (val .reg .BC >= ((Float64_bias + Float64_i64_max_exp ) << Float64_exp_BC_shift )) {
138
- #if HANDLE_INT_MIN != 0
139
- /* if the value truncates to INT64_MIN */
140
- if (x_sign && val .bin == UINT64_C (0x43E0000000000000 )) {
141
- return INT64_MIN ;
142
- }
143
- #endif
110
+ if (val .reg .BC >= ((Float64_bias + Float64_u64_max_exp ) << Float64_exp_BC_shift )) {
144
111
/* undefined return value for underflow/overflow/inf/NaN values of x */
145
112
return 0 ;
146
113
}
@@ -150,19 +117,18 @@ int64_t _dtoll_c(f64_sign arg) {
150
117
return ret ;
151
118
}
152
119
120
+ /**
121
+ * @brief the exact same routine is used for (long)long double and
122
+ * (unsigned long)long double. If the input long double is out of range,
123
+ * then the conversion is UB anyways.
124
+ */
153
125
int32_t _dtol_c (f64_sign arg ) {
154
126
F64_pun val ;
155
127
bool x_sign = arg .sign ;
156
128
val .flt = arg .flt ;
157
129
158
130
/* overflow || isinf(x) || isnan(x) */
159
- if (val .reg .BC >= ((Float64_bias + Float64_i32_max_exp ) << Float64_exp_BC_shift )) {
160
- #if HANDLE_INT_MIN != 0
161
- /* if the value truncates to INT32_MIN */
162
- if (x_sign && val .bin <= UINT64_C (0x41E00000001FFFFF )) {
163
- return INT32_MIN ;
164
- }
165
- #endif
131
+ if (val .reg .BC >= ((Float64_bias + Float64_u32_max_exp ) << Float64_exp_BC_shift )) {
166
132
/* undefined return value for underflow/overflow/inf/NaN values of x */
167
133
return 0 ;
168
134
}
0 commit comments