From 194c67c3c8bad703f62d8f1294c11eb847764428 Mon Sep 17 00:00:00 2001 From: stefanf Date: Fri, 27 May 2005 10:00:22 +0000 Subject: Fix long (and long long) to long double, unsigned to long double and unsigned long (and unsigned long long) to long double conversions. - Add a parameter that specifies the position of the sign bit to the _QP_TTOQ macro, previously it always looked at bit 31. Pass a negative number to disable sign inspection for unsigned types. This fixes _Qp_xtoq(), _Qp_uitoq() and _Qp_uxtoq(). - In the functions __fpu_itof() and __fpu_xtof(), look at the sign bit to decide whether we're doing a conversion from an unsigned type. If so, don't negate the mantissa if the integer exceeds the biggest signed number. PR: 55773 Patch by: Stephen Paskaluk (based upon) MFC after: 2 weeks --- lib/libc/sparc64/fpu/fpu_explode.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'lib/libc/sparc64/fpu/fpu_explode.c') diff --git a/lib/libc/sparc64/fpu/fpu_explode.c b/lib/libc/sparc64/fpu/fpu_explode.c index 7c1f3eb..09f8908 100644 --- a/lib/libc/sparc64/fpu/fpu_explode.c +++ b/lib/libc/sparc64/fpu/fpu_explode.c @@ -101,7 +101,14 @@ __fpu_itof(fp, i) * fpu_norm()'s handling of `supernormals'; see fpu_subr.c. */ fp->fp_exp = FP_LG; - fp->fp_mant[0] = (int)i < 0 ? -i : i; + /* + * The sign bit decides whether i should be interpreted as + * a signed or unsigned entity. + */ + if (fp->fp_sign && (int)i < 0) + fp->fp_mant[0] = -i; + else + fp->fp_mant[0] = i; fp->fp_mant[1] = 0; fp->fp_mant[2] = 0; fp->fp_mant[3] = 0; @@ -127,7 +134,14 @@ __fpu_xtof(fp, i) * fpu_norm()'s handling of `supernormals'; see fpu_subr.c. */ fp->fp_exp = FP_LG2; - *((int64_t*)fp->fp_mant) = (int64_t)i < 0 ? -i : i; + /* + * The sign bit decides whether i should be interpreted as + * a signed or unsigned entity. + */ + if (fp->fp_sign && (int64_t)i < 0) + *((int64_t*)fp->fp_mant) = -i; + else + *((int64_t*)fp->fp_mant) = i; fp->fp_mant[2] = 0; fp->fp_mant[3] = 0; __fpu_norm(fp); -- cgit v1.1