Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!seismo!ll-xn!cullvax!drw From: drw@cullvax.UUCP Newsgroups: comp.lang.forth Subject: Need Forth Sort Message-ID: <1056@cullvax.UUCP> Date: Wed, 8-Apr-87 10:57:51 EST Article-I.D.: cullvax.1056 Posted: Wed Apr 8 10:57:51 1987 Date-Received: Sat, 11-Apr-87 08:01:25 EST Organization: Cullinet Software, Inc., Westwood, MA Lines: 38 tbg@apollo.uucp (Tom Gross) writes: > Actually what I need is something that will check > four words on the stack to see if at least three > of them are approximately equal, and return the > average of the approximately equal ones and a flag > indicating whether there were at least 3 approximately > equal values found (or garbage and a flag indicating > that there were not 3 values approximately equal). Don't bother to sort the values. That will take a theoretical minimum of 5 comparisons, whereas testing all pairs for approximate equality will only take 6. (Assuming that approximate equality testing is not much slower than greater/less testing.) Test all 6 pairs (straight-line code) for approximate equality, and keep count of the number of pairs that pass. If at least 3 pairs pass, then you have a good case. But... If the 4 numbers are A, B, C, and D, it could be that the following sets of pairs test approximately equal: Case 1: AB BC AC (so D's the odd man out) Case 2: AB BC CD (because A and D are just a little too far apart) Determining the average value can be tricky, because you aren't guaranteed that there is a uniquely defined set of values all of which are approximately equal to each other, and none of which are approximately equal to anything outside the set. E.g., in case 2 above, which numbers do you average? And why is your text indented 5 spaces? It's a waste! Dale -- Dale Worley Cullinet Software UUCP: ...!seismo!harvard!mit-eddie!cullvax!drw ARPA: cullvax!drw@eddie.mit.edu Un*x (a generic name for a class of OS's) != Unix (AT&T's brand of such)