This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Irix6 long doubles implemented wrong? (27_io/ostream_inserter_arith)


On Jan 28, 2003, Alexandre Oliva <aoliva@redhat.com> wrote:

> To invert: ???  this is the missing bit :-(

> To divide, invert the divisor and multiply.

Just figured out how to do division, using addition, subtraction and
multiplication:

- obtain an initial estimate of the result by dividing the high
  parts

- compute a residue by subtracting from the dividend the result of
  multiplying the result estimate and the divisor

- divide the high part of the residue by the high part of the divisor,
  and add it to the result

- repeat the last two steps until the result stops changing


I think it doesn't take more than 2 iterations for the result to
stabilize.  Here's the pseudo code:

long double divide(long double in1, long double in2) {
  long double result, prev;

  result.high = in1.high / in2.high;

  if (isinf (result.high) || isnan (result.high)) {
    result.low = result.high;
    return result;
  }

  result.low = 0.0;

  do {
    long double partial;
    prev = result;
    partial.high = (in1 - result * in2).high / in2.high;
    partial.low = 0.0;
    result += partial;
  } while (result != prev);

  return result;
}


Other operations, such as extending from double, compares, etc, are
pretty obvious, so I'll refrain from posting them here.  Conversion
to/from int can be done with extension to/truncation from double, and
conversion to/from long long takes a bit more work to use all 64 bits,
but that's it.  Wheee!

Any candidates to implement say gcc/config/tp-ibmext-bit.c using these
ideas, even though we have no immediate use for them?

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]