qsort() results: implementation dependent?



Hi everybody,

suppose you have to order a list of integers which refer to points
located in the 3D space. The compare() function is based on the
distance that these points have with respect to the origin (0,0,0). So,
using the standart qsort() function, I think this task should be
accomplished as follows:

qsort(int_vector, (size_t)no_of_points, sizeof(int), compare_function);

where

static int compare_function(void *b0, const void *b1)
{
double eps = 1e-6;

int pnt0 = *((int *)b0);
int pnt1 = *((int *)b1);

double d0 = get_distance(pnt0);
double d1 = get_distance(pnt1);

double dd = d0 - d1;

if(dd > eps)
return 1;
else if (dd < -eps)
return -1;
else
return 0.;

}

The question is: why two different qsort() implementations (AIX and
Linux) should give different results? In particular, the Linux
implementation seems to fail to to find the right order. Any hint?
Thanks
Max

.



Relevant Pages

  • Re: How Common Lisp sucks
    ... Except that Linux has a process for managing change, ... SBCL, CLISP, Allegro, etc. are implementations of Common Lisp. ... The POSIX standard is analogous to the hyperspec. ... the Posix community has processes for developing and evolving ...
    (comp.lang.lisp)
  • Re: How Common Lisp sucks
    ... Except that Linux has a process for managing change, ... SBCL, CLISP, Allegro, etc. are implementations of Common Lisp. ... is what's important for understanding my analogy. ... The POSIX standard is analogous to the hyperspec. ...
    (comp.lang.lisp)
  • Re: COM alternative in Linux & UNIX world?
    ... Linux and UNIX. ... I have chosen COM interface, because one can call my app ... Microsoft's COM and DCOM are implementations of the ONC DCE/RPC ... select one of the many DCE or CORBA implementations available at ...
    (comp.os.linux.development.apps)
  • Re: Xen & VMI?
    ... ABI promise: VMI. ... The only thing needed is to treat the Linux ... BIOS implementations all implementing just enough of the various BIOS ...
    (Linux-Kernel)
  • Re: Child Process Monitor for intercepting File IO
    ... On many implementations this is the ptraceAPI. ... > If your OS supports the concept of nested file systems or file system ... its the Linux tools I am mainly interested in providing for. ...
    (comp.unix.programmer)