[PATCH] frexpl: Support smaller long double.

Takashi Yano takashi.yano@nifty.ne.jp
Thu Dec 2 09:50:18 GMT 2021


On Thu, 02 Dec 2021 09:07:43 +0100
Paul Zimmermann wrote:
> about https://sourceware.org/pipermail/newlib/2021/018738.html:
> 
> > This patch add support for smaller long double, LDBL_MANT_DIG is 24 or 53.
> 
> are you sure LDBL_MANT_DIG can be 24 in radix 2? As far as I know, the standard
> requires LDBL_DIG >= 10, and a floating-point number with LDBL_DIG decimal
> digits should be converted to a long double and back to LDBL_DIG digits
> without any modification, which requires LDBL_MANT_DIG >= 34.
> 
> Also the standard says in 6.2.5: "the set of values of the
> type double is a subset of the set of values of the type long double."

Thanks for pointing out this.

I now have read ISO/IEC9899 standard draft, and confirm that it requires
LDBL_DIG >= 10. It also says DBL_DIG >= 10. If this means LDBL_MANT_DIG
and DBL_MANT_DIG >= 34, double also should not be DBL_MANT_DIG == 24.

However, newlib supports _DOUBLE_IS_32BITS. I guess some platfors
does not comply with the standard. So I consider long double can be
smaller in such platforms. However if both double and long double are
32bit, frexpl() calls frexp() (double version). So this patch does more
than necessary.

I will submit v2 patch, which removes following LDBM_MANT_DIG == 24
case.

+# if (LDBL_MANT_DIG == 24) /* 32-bit long double */
+static const double scale = 0x1p25;
+
+union ldbl {
+  long double x;
+  struct {
+#  ifdef __IEEE_LITTLE_ENDIAN /* for Intel CPU */
+    __uint32_t frac:23;
+    __uint32_t exp:8;
+    __uint32_t sign:1;
+#  endif
+#  ifdef __IEEE_BIG_ENDIAN
+#   ifndef ___IEEE_BYTES_LITTLE_ENDIAN
+    __uint32_t sign:1;
+    __uint32_t exp:8;
+    __uint32_t frac:23;
+#   else /* ARMEL without __VFP_FP__ */
+    __uint32_t frac:23;
+    __uint32_t exp:8;
+    __uint32_t sign:1;
+#   endif
+#  endif
+  } u32;
+};

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>


More information about the Newlib mailing list