public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* tr1::unordered_set<double> bizarre rounding behavior (x86)
@ 2005-07-05 13:05 Michael Veksler
  2005-07-05 13:32 ` Paolo Carlini
                   ` (2 more replies)
  0 siblings, 3 replies; 32+ messages in thread
From: Michael Veksler @ 2005-07-05 13:05 UTC (permalink / raw)
  To: gcc





Hello,

In previous discussions on rounding of double on x86 I wanted
to find an example that points to the absurdity of current
gcc behavior.
At last I found such an example:

---- t.cpp start ---
#include <tr1/unordered_set>
#include <iostream>

double x=3.0;

int main()
{
   std::tr1::unordered_set<double> myset;
   myset.insert(2/x);
   myset.insert(2/x);
   std::cout << myset.size() << " elements\n";
   if (myset.size() > 1)
      std::cout << "Are last and first equal?  "
                << std::boolalpha
                << ( *myset.begin() == *++myset.begin())
                << "\n";
   return 0;
}
--- t.cpp  end ---

Here is what I get (Pentium 4):

--- trace begin ---
test$ /opt/gcc-4.0-20050602/bin/g++ t.cpp
test$ ./a.out
1 elements
test$ /opt/gcc-4.0-20050602/bin/g++ -O3 -finline-limit=1000000 t.cpp
test$ ./a.out
2 elements
Are last and first equal?  true
--- trace end ---

The behavior of the second run does not look right. What does it mean?
1. Is it forbidden by tr1 to define unordered_set<double> ?
2. Is it a bug in the tr1 document (which should have forbidden this).
3. Is it OK to have repetitions in unordered_set?
4. Is it a bug in gcc, for handling double the way it does?
5. Is it a bug in the implementation of tr1 in libstdc++ ?
    Maybe handling of double should move to a different
    translation unit, to avoid aggressive inlining. Or maybe
    there should be a specialization for equal_to<double>,
    where error bands will be used.


Using error bands will work fine for unordered_set<doble> insertion.
It may lead to the "loss" of close entries, but in case of double it sounds
reasonable.


P.S.
   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 ?).

  Michael

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2005-07-06 13:50 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-05 13:05 tr1::unordered_set<double> bizarre rounding behavior (x86) 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
2005-07-05 18:12     ` Paolo Carlini
2005-07-05 19:58       ` Joe Buck
2005-07-05 19:59         ` Paolo Carlini

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