------- Comment #8 from amodra at bigpond dot net dot au  2006-01-28 00:17 
-------
There is no reason to say that wrong long double -> float conversion code
emitted by gcc is some fault of the long double design.  It is relatively easy
to convert correctly:

float long_double_to_float (long double a)
{
  union { long double ld; double d[2]; } u;
  double xh, xl, tmp;
  float res;

  u.ld = a;
  xh = u.d[0];
  xl = u.d[1];

  /* Convert high double.  */
  res = (float) xh;
  /* Subtract from long double, and canonicalise result.  */
  xh -= res;
  tmp = xh + xl;
  xl = (xh - tmp) + xl;
  xh = tmp;
  /* Convert remainder.  */
  res += (float) xh;
  return res;
}

There are some obvious simplifications to be made to the above function.  I
left the dead code there to show a technique that is useful in many long double
algorithms, ie. operate on high double, subtract result and canonicalise,
operate on low double (which has moved to xh by virtue of canonicalisation).


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25661

Reply via email to