Message-ID: <388CBFA9.3E47603C@cyberoptics.com> From: Eric Rudd Organization: CyberOptics X-Mailer: Mozilla 4.08 [en] (Win95; U) MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: qsort() bug? Or invalid usage??? References: <867gpd$k0u$1 AT nets3 DOT rz DOT RWTH-Aachen DOT DE> <388758A7 DOT 1B64BDF9 AT cyberoptics DOT com> <388824A4 DOT 7E8CA268 AT is DOT elta DOT co DOT il> <869q6i$ika$1 AT nets3 DOT rz DOT RWTH-Aachen DOT DE> <38887BFB DOT 2D3FA7A6 AT cyberoptics DOT com> <86a76a$nro$1 AT nets3 DOT rz DOT RWTH-Aachen DOT DE> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 39 Date: Mon, 24 Jan 2000 15:10:01 -0600 NNTP-Posting-Host: 38.196.93.9 X-Trace: client 948748203 38.196.93.9 (Mon, 24 Jan 2000 16:10:03 EST) NNTP-Posting-Date: Mon, 24 Jan 2000 16:10:03 EST To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Hans-Bernhard Broeker wrote: > > 2) did a "fuzzy" sort with a "fuzzy" comparison function. > > But that wouldn't be 'sorting' any longer. Not even to mention that > anno domini 1989, I don't think the 'fuzzy' hype had already > happened... By "fuzzy" I mean that the order of two elements in the sorted array is unspecified if they are close to the same value, but properly-sorted otherwise. > Just some minor comments regarding that comparison function you show: > > > x = atof((const char *) a); > > y = atof((const char *) b); > > Bad idea. atof()ing the same string more than once is a waste of time > and effort. I agree that it's suboptimal from the standpoint of execution time, but it avoids having to declare a separate array to hold the floating-point values. > And, of course, the potential of getting the comparison wrong would > become smaller without the atof() calls, too. According to the ANSI standard (as far as I can tell), neither approach would be guaranteed to work. I may bring this up in comp.std.c, because I can't see any way to write a strictly-conforming routine that uses qsort to sort floating-point values. However, over the weekend I found that the current DJGPP qsort works just fine even in the presence of an inexact comparison routine. (See my other posting in this thread.) -Eric Rudd rudd AT cyberoptics DOT com