Skip to content

Commit 7eb3264

Browse files
[libc] Add handling for long double=double double (#113235)
For Hand-In-Hand we need float to string to support a wider set of architectures, specifically the ones that libc++ supports. This includes powerpc, which apparently uses "double double" as its long double type. Since Hand-In-Hand isn't currently using long double, this just opts them out.
1 parent 23b18fa commit 7eb3264

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

libc/src/__support/macros/properties/types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#define LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80
2828
#elif (LDBL_MANT_DIG == 113)
2929
#define LIBC_TYPES_LONG_DOUBLE_IS_FLOAT128
30+
#elif (LDBL_MANT_DIG == 103)
31+
#define LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
3032
#endif
3133

3234
// int64 / uint64 support

libc/src/__support/str_to_float.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,10 @@ eisel_lemire(ExpandedFloat<T> init_num,
195195
return output;
196196
}
197197

198-
#if !defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64)
198+
// TODO: Re-enable eisel-lemire for long double is double double once it's
199+
// properly supported.
200+
#if !defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64) && \
201+
!defined(LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE)
199202
template <>
200203
LIBC_INLINE cpp::optional<ExpandedFloat<long double>>
201204
eisel_lemire<long double>(ExpandedFloat<long double> init_num,
@@ -316,7 +319,8 @@ eisel_lemire<long double>(ExpandedFloat<long double> init_num,
316319
output.exponent = exp2;
317320
return output;
318321
}
319-
#endif // !defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64)
322+
#endif // !defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64) &&
323+
// !defined(LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE)
320324

321325
// The nth item in POWERS_OF_TWO represents the greatest power of two less than
322326
// 10^n. This tells us how much we can safely shift without overshooting.
@@ -518,6 +522,18 @@ template <> class ClingerConsts<long double> {
518522
static constexpr long double MAX_EXACT_INT =
519523
10384593717069655257060992658440191.0L;
520524
};
525+
#elif defined(LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE)
526+
// TODO: Add proper double double type support here, currently using constants
527+
// for double since it should be safe.
528+
template <> class ClingerConsts<long double> {
529+
public:
530+
static constexpr double POWERS_OF_TEN_ARRAY[] = {
531+
1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11,
532+
1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22};
533+
static constexpr int32_t EXACT_POWERS_OF_TEN = 22;
534+
static constexpr int32_t DIGITS_IN_MANTISSA = 15;
535+
static constexpr double MAX_EXACT_INT = 9007199254740991.0;
536+
};
521537
#else
522538
#error "Unknown long double type"
523539
#endif

0 commit comments

Comments
 (0)