Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Common Sort Routines Broken, can't find story.
#1
Did anyone else see the story recently about why almost all common sorting routines are broken?

The problem they were talking about was the average problem.

IE

(a+b)/2 .. Which fails when a+b make a number bigger than can fit the datatype.

The solution they recommended was

(a/2)+(b/2)

Does anyone know where this page was? I've been searching google, but can't find it. I found one page of interest, but it wasn't what I was looking for. Heres the one i found interesting anyway.

http://www.angelfire.com/pq/jamesbarbett...Broken.htm
EVEN MEN OF STEEL RUST.
[Image: chav.gif]
Reply
#2
Yeah, I saw it too, but I can't remember where.

The only time it didn't work was on really large sets, though, where the add-then-divide method would overflow a 32-bit int. I thought it was on Raymond Chen's blog, but I couldn't find it...
Reply
#3
ah, that makes sense as i read that blog too. I'll have to have a harder search.

Yes, of course you are right that it would be rare to have a set that large. I just remember it had some more details of common mistakes like this, and I wanted to read them again, just to refresh.
EVEN MEN OF STEEL RUST.
[Image: chav.gif]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)