Re: C++ more efficient than C?
- From: richard@xxxxxxxxxxxxxxx (Richard Tobin)
- Date: 9 Apr 2008 20:10:07 GMT
In article <c74c2$47fd1188$24555@xxxxxxxxxxxxxxxxx>,
Dann Corbit <dcorbit@xxxxxxxxx> wrote:
Suppose we have x, x+e, and x+2e, x+3e, x+4e. Your comparison
function may sort them as x+4e, x+3e, x+2e, x+e, x. Now you search
for x. bsearch() will compare it with x+2e, and find it's less. It
will then compare it with x+3e and x+4e, and conclude that it is not
present in the array. It will give the wrong answer.
Assuming that this is the wrong answer is a mistake. If you are searching
for:
x+2e
and you find:
x+4e
then you found the number that you were searching for, if it is floating
point. If you are not happy with that answer then you should not use
floating point.
Read more carefully. It doesn't find the wrong entry. It wrongly
says there is no such value in the array. According to you, there are
several, but it doesn't find *any* of them.
It says it must be a total order. Yours isn't.
Achieving total order is literally not possible, because floating point is
inexact. This statement is absolutely true.
Then you'd better not use floating point with qsort().
-- Richard
--
:wq
.
- Follow-Ups:
- Re: C++ more efficient than C?
- From: Dann Corbit
- Re: C++ more efficient than C?
- References:
- C++ more efficient than C?
- From: copx
- Re: C++ more efficient than C?
- From: Dann Corbit
- Re: C++ more efficient than C?
- From: Richard Tobin
- Re: C++ more efficient than C?
- From: Dann Corbit
- C++ more efficient than C?
- Prev by Date: Re: C++ more efficient than C?
- Next by Date: Re: function pointer
- Previous by thread: Re: C++ more efficient than C?
- Next by thread: Re: C++ more efficient than C?
- Index(es):
Relevant Pages
|