public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alexandre Oliva <aoliva@redhat.com>
To: "Kaveh R. Ghazi" <ghazi@caip.rutgers.edu>
Cc: gcc-bugs@gcc.gnu.org, gcc-patches@gcc.gnu.org, gcc@gcc.gnu.org,
	libstdc++@gcc.gnu.org, oldham@codesourcery.com,
	ro@TechFak.Uni-Bielefeld.DE, rth@redhat.com
Subject: Re: Irix6 long doubles implemented wrong? (27_io/ostream_inserter_arith)
Date: Tue, 28 Jan 2003 17:32:00 -0000	[thread overview]
Message-ID: <orel6xqlw9.fsf@free.redhat.lsd.ic.unicamp.br> (raw)
In-Reply-To: <or7kcsjkdu.fsf@free.redhat.lsd.ic.unicamp.br>

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

> On Jan 19, 2003, Alexandre Oliva <aoliva@redhat.com> wrote:
>> the minimum normal exponent should be set such that all 107
>> significant bits are available (and it's 107, not 106, as I
>> implemented it) for normals.

> It can't possibly be 107.

On second (or rather nth) thought, it possibly can, if you take
advantage of the sign bit of the second double.  But then you have to
allow it to be different from the sign of the first double, which we
don't, and the conversion routines would have to be tweaked to take
advantage of it without losing the additional bit of precision.

Furthermore, a way to implement most of the emulation without having
to use integers has occurred to me.  Here's the idea.

For addition of two long-doubles composed of a pair of doubles

- add the most significant double of each number.  If the result is
  infinity, NaN, copy it to the second double of the result and
  you're done

- otherwise, figure out which of the numbers you're adding has the
  biggest exponent.  Take a copy of the result obtained so far into a
  temporary say tmp and, from it, subtract the most significant double
  of each of the input operands.  Now this temporary contains the
  negated value of whatever bits there were in the high doubles that
  had to be thrown away due to rounding or limited precision from the
  high part of the result.

- assign to the low part of the result the result of adding the
  negated temporary, the low doubles of the input operands, highest
  exponent first

in pseudo-code (untested):

long double tfadd (long double in1, long double in2) {
  long double result;
  double tmp;

  result.high = in1.high + in2.high;

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

  result.low = in1.low + in2.low;

  if (in1.exponent < in2.exponent)
    result.low -= result.high - in1.high - in2.high;
  else
    result.low -= result.high - in2.high - in1.high;

  return result;
}


For negation, just negate each double individually.

For subtraction, negate the second operand and add.

For widening multiplication (double x double -> long double):

- multiply the doubles into the high part of the result

- if the result is infinity, a nan or zero, copy the high part of the
  low part and stop.

- divide the result by one of the input doubles into tmp1

- subtract the other input double from tmp1 into tmp2

- multiply tmp2 by the other input double into the low part of the
  result

long double tfdfmult (double in1, double in2) {
  long double result;

  result.high = in1 * in2;

  if (isinf (result.high) || isnan (result.high) || result.high == 0.0)
    result.low = result.high;
  else
    result.low = (result.high / in1 - in2) * in1;

  return result;
}


For multiplication of two long doubles:

- widen-multiply each pair of doubles, and add the results from least
  to most significant.

long double tfmult (long double in1, long double in2) {
  if (exponent (in1) < exponent (in2))
    swap (in1, in2);

  return tfdfmult (in1.low, in2.low)  + tfdfmult (in1.low, in2.high)
       + tfdfmult (in1.high, in2.low) + tfdfmult (in1.high, in2.high);
}


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

To divide, invert the divisor and multiply.


For the numerical experts, are there any flaws in the procedures
above?  Any ideas on how to implement inversion without losing
(much) precision?

-- 
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

  reply	other threads:[~2003-01-28 16:29 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-14 14:09 Kaveh R. Ghazi
2002-12-16  9:24 ` Rainer Orth
2002-12-16  9:51 ` Alexandre Oliva
2002-12-16  9:52   ` Rainer Orth
2002-12-16 12:23     ` Eric Christopher
2002-12-16 21:58   ` Kaveh R. Ghazi
2002-12-21 10:45     ` Alexandre Oliva
2002-12-22  6:02       ` Kaveh R. Ghazi
2002-12-22 10:24       ` Alexandre Oliva
2002-12-22 10:35         ` Alexandre Oliva
2002-12-23  9:46         ` Alexandre Oliva
2002-12-24 11:07           ` Kaveh R. Ghazi
2002-12-25  8:04             ` Alexandre Oliva
2002-12-26 13:48               ` Alexandre Oliva
2002-12-27  7:06                 ` Alexandre Oliva
2002-12-29  0:22                   ` Kaveh R. Ghazi
2002-12-29  6:06                     ` Alexandre Oliva
2003-01-07 22:57                   ` Richard Henderson
2003-01-08 18:16                     ` Alexandre Oliva
2003-01-08 22:19                       ` Richard Henderson
2003-01-09  9:29                         ` Alexandre Oliva
2003-01-09  9:38                           ` Alexandre Oliva
2003-01-10  1:18                     ` Alexandre Oliva
2003-01-10  2:29                       ` Richard Henderson
2003-01-19 21:02                         ` Kaveh R. Ghazi
2003-01-19 22:15                           ` Alexandre Oliva
2003-01-26 13:00                             ` Alexandre Oliva
2003-01-28 17:32                               ` Alexandre Oliva [this message]
2003-01-28 23:38                                 ` Alexandre Oliva
2003-01-26 15:20                             ` Alexandre Oliva
2003-01-26 16:14                               ` Alexandre Oliva
2003-01-26 18:40                                 ` Kaveh R. Ghazi
2003-01-26 21:24                                 ` Kaveh R. Ghazi
2003-01-26 21:25                                   ` Alexandre Oliva
2003-01-27  9:17                                   ` Kaveh R. Ghazi
2003-01-27 10:40                                     ` Alexandre Oliva
2003-01-28  4:52                                       ` Kaveh R. Ghazi
2003-01-28 17:31                                         ` Alexandre Oliva
2003-01-28 19:11                                           ` Kaveh R. Ghazi
2003-01-28 19:23                                             ` Kaveh R. Ghazi
2003-01-28 19:47                                               ` Rainer Orth
     [not found]                                               ` <15926.49701.3! 59482.666471@xayide.TechFak.Uni-Bielefeld.DE>
2003-01-29  6:56                                                 ` Kaveh R. Ghazi
2003-01-29 10:07                                                   ` Richard Henderson
2003-01-29 13:39                                                     ` Alexandre Oliva
2003-01-29 17:26                                                     ` Kaveh R. Ghazi
2003-01-29 18:10                                                       ` Richard Henderson
2003-01-30 23:31                                                         ` Irix6 native long double libcalls progress report (and problem) Kaveh R. Ghazi
2003-01-30 23:49                                                           ` Richard Henderson
2003-02-03 13:22                                                             ` Alexandre Oliva
2003-01-30  8:05                                                     ` Irix6 long doubles implemented wrong? (27_io/ostream_inserter_arith) Kaveh R. Ghazi
2003-02-03 13:07                                                       ` Alexandre Oliva
2003-02-03 15:18                                                         ` Kaveh R. Ghazi
2003-02-03 16:37                                                           ` Alexandre Oliva
2003-01-27 10:41                                     ` Alexandre Oliva
2003-01-26 21:54                                 ` Richard Henderson
2003-01-10  1:37                     ` Alexandre Oliva
2003-01-26 10:07                     ` Alexandre Oliva
2003-01-26 10:42                     ` Alexandre Oliva
2003-01-26 10:45                     ` Alexandre Oliva
2003-01-26 10:53                     ` Alexandre Oliva
2003-01-26 12:07                     ` Alexandre Oliva
2003-01-26 12:20                     ` Alexandre Oliva
2003-01-26 12:50                     ` Alexandre Oliva
2002-12-24 18:15           ` Kaveh R. Ghazi
2003-01-07 22:16             ` Richard Henderson
2003-01-07 22:40           ` Richard Henderson
2003-01-08 18:04             ` Alexandre Oliva
2003-01-08 22:29               ` Richard Henderson
2003-01-08 22:46                 ` Zack Weinberg
2003-01-08 23:13                   ` Richard Henderson
2003-01-09  7:27                 ` Alexandre Oliva
2002-12-17  0:18 Billinghurst, David (CRTS)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=orel6xqlw9.fsf@free.redhat.lsd.ic.unicamp.br \
    --to=aoliva@redhat.com \
    --cc=gcc-bugs@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gcc@gcc.gnu.org \
    --cc=ghazi@caip.rutgers.edu \
    --cc=libstdc++@gcc.gnu.org \
    --cc=oldham@codesourcery.com \
    --cc=ro@TechFak.Uni-Bielefeld.DE \
    --cc=rth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).