public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Joe Buck <Joe.Buck@synopsys.COM>
To: Paolo Carlini <pcarlini@suse.de>
Cc: Michael Veksler <VEKSLER@il.ibm.com>, gcc@gcc.gnu.org
Subject: Re: tr1::unordered_set<double> bizarre rounding behavior (x86)
Date: Tue, 05 Jul 2005 18:08:00 -0000	[thread overview]
Message-ID: <20050705180759.GA2315@synopsys.com> (raw)
In-Reply-To: <42CABDCC.3070508@suse.de>

On Tue, Jul 05, 2005 at 07:05:16PM +0200, Paolo Carlini wrote:
> Michael Veksler wrote:
> 
> >   std::tr1::hash<dobule> is implemented in a very bad way.
> >   it casts double to size_t, which of course does a very poor job on big
> >   values (is the result of 1.0e100 cast to size_t defined ?).
> >  
> >
> A possible solution would be using frexp & co to extract the mantissa
> and then work on it, one way or the other. You can find it proposed
> around. Then, often the exponent is simply discarded.
> 
> What do you think?

Close, but not quite.

Hash functions are, by nature, many-to-one.  A good hash function has
few collisions for values that frequently appear; the program will preform
very poorly if many inputs hash to the same value.  The existing function
will make all values over max(size_t) collide (assuming the cast clips).
Using only the mantissa is better, but if doubles are used to
represent fixed-point, then common values like 0.25, 0.5, 1, 2, 4 might
all be in the hash table, and they will collide.

You could do frexp, scale the mantissa to form an integer (e.g. multiply
by a large integer), then add it (modulo 2**n) to some prime number
multiplied by the exponent.  This should give good spreading for both
large values and exactly representable values.

  parent reply	other threads:[~2005-07-05 18:08 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
2005-07-05 19:24         ` Gabriel Dos Reis
2005-07-06 12:38     ` Avi Kivity
2005-07-06 12:54       ` Michael Veksler
2005-07-06 13:01         ` Avi Kivity
2005-07-06 13:50           ` Gabriel Dos Reis
2005-07-06 12:54       ` Gabriel Dos Reis
2005-07-05 18:08   ` Joe Buck [this message]
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=20050705180759.GA2315@synopsys.com \
    --to=joe.buck@synopsys.com \
    --cc=VEKSLER@il.ibm.com \
    --cc=gcc@gcc.gnu.org \
    --cc=pcarlini@suse.de \
    /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).