public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Michael Veksler <VEKSLER@il.ibm.com>
To: Joe Buck <Joe.Buck@synopsys.COM>
Cc: gcc@gcc.gnu.org, Gabriel Dos Reis <gdr@integrable-solutions.net>
Subject: Re: tr1::unordered_set<double> bizarre rounding behavior (x86)
Date: Tue, 05 Jul 2005 19:01:00 -0000	[thread overview]
Message-ID: <OFC50D7347.1C4339A9-ONC2257035.0066952B-C2257035.0068790B@il.ibm.com> (raw)
In-Reply-To: <20050705181025.GB2315@synopsys.com>





Joe Buck <Joe.Buck@synopsys.COM> wrote on 05/07/2005 21:10:25:

> On Tue, Jul 05, 2005 at 08:05:39PM +0200, Gabriel Dos Reis wrote:
> > It is definitely a good thing to use the full bits of value
> > representation if we ever want to make all "interesting" bits part of
> > the hash value.  For reasonable or sane representations it suffices to
> > get your hand on the object representation, e.g.:
> >
> >    const int objsize = sizeof (double);
> >    typedef unsigned char objrep_t[objsize];
> >    double x = ....;
> >    objrep_t& p = reintepret_cast<objrep_t&>(x);
> >    // ...
> >
> > and let frexp and friends only for less obvious value representation.
>
> I disagree; on an ILP32 machine, we pull out only 32 bits for the hash
> value, and if you aren't careful, your approach will wind up using the
> least significant bits of the mantissa.  This will cause all values that
> are exactly representable as floats to collide.

For that you can do something like (or templated equivalent):
namespace Impl
{
 template <class T>
 size_t floating_point_hash(T in)
 {
   if (sizeof(in) <= sizeof(size_t))
    Use Gaby's solution, with zero padding;
   else
    frexp and friends using Joe Buck's ideas;
  }
}

Gaby's solution should be done with care - to avoid any
aliasing issues (never go directly from double& to size_t&).

Both Gaby's and Joe Buck's solutions do not take
the strangeness of IEEE (NNN?) into account.
As I remember it (I don't have the reference at home),
IEEE FP has many bit-representations for NaN, each
containing some bit-encoding of errors.
It has been years since I last saw the standard of IEEE FP,
so I may give wrong details, but the main idea should be
correct.

"There *should* be a specialization for equal_to<double> that
provides a strict weak ordering for NaNs as well as other
values." [quoted forwarded mail from P.J. Plauger]
Doing bit-wise conversions will not address this requirement.

  Michael

  parent reply	other threads:[~2005-07-05 19:01 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-05 13:05 Michael Veksler
2005-07-05 13:32 ` Paolo Carlini
2005-07-05 15:43   ` Michael Veksler
2005-07-05 15:57     ` Gabriel Dos Reis
2005-07-05 16:04       ` Paolo Carlini
2005-07-05 20:18         ` Michael Veksler
2005-07-05 20:22           ` Paolo Carlini
2005-07-05 20:36     ` Michael Veksler
2005-07-05 20:41       ` Paolo Carlini
2005-07-05 20:47         ` Paolo Carlini
2005-07-05 21:12           ` Michael Veksler
2005-07-05 21:21       ` Gabriel Dos Reis
2005-07-05 14:28 ` Gabriel Dos Reis
2005-07-05 17:04 ` Paolo Carlini
2005-07-05 18:06   ` Gabriel Dos Reis
2005-07-05 18:10     ` Joe Buck
2005-07-05 18:32       ` Gabriel Dos Reis
2005-07-05 18:42         ` Paolo Carlini
2005-07-05 19:18           ` Gabriel Dos Reis
2005-07-05 19:52             ` Paolo Carlini
2005-07-05 20:24               ` Gabriel Dos Reis
2005-07-05 19:01       ` Michael Veksler [this message]
2005-07-05 19:24         ` Gabriel Dos Reis
2005-07-06 12:38     ` Avi Kivity
2005-07-06 12:54       ` Gabriel Dos Reis
2005-07-06 12:54       ` Michael Veksler
2005-07-06 13:01         ` Avi Kivity
2005-07-06 13:50           ` Gabriel Dos Reis
2005-07-05 18:08   ` Joe Buck
2005-07-05 18:12     ` Paolo Carlini
2005-07-05 19:58       ` Joe Buck
2005-07-05 19:59         ` Paolo Carlini

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=OFC50D7347.1C4339A9-ONC2257035.0066952B-C2257035.0068790B@il.ibm.com \
    --to=veksler@il.ibm.com \
    --cc=Joe.Buck@synopsys.COM \
    --cc=gcc@gcc.gnu.org \
    --cc=gdr@integrable-solutions.net \
    /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).