﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	severity	resolution	keywords	cc
326	psVectorSort doesn't	Paul Price	robert.desonia@…	"Calling psVectorSort with a psVector of type F32 yields a vector with the
elements in the same order as the input:

Input vector:
0.186915 0.951040 0.545436 0.074626 0.229219 0.522971 0.092768
Sorted vector:
0.186915 0.951040 0.545436 0.074626 0.229219 0.522971 0.092768

This is because the comparison function is effectively:
int psCompareF32(float a, float b) {
    return a - b;
}

Note that, for the above list of numbers (the absolute difference between any of
which is always less than unity), this comparison function will always return 0
(meaning that all the values are equal).  The comparison function should be
something like:

int psCompareF32(float a, float b)
{
    float diff = a - b;
    return (diff > 0.0) ? +1 : ((diff < 0.0) ? -1 : 0);

}



Code used for test:

#include <stdio.h>
#include ""pslib.h""

#define SIZE 7

int main(int argc, char *argv[])
{
    psTraceSetLevel(""."", 10);

    psRandom *random = psRandomAlloc(PS_RANDOM_TAUS, 1);
    psVector *vector = psVectorAlloc(SIZE, PS_TYPE_F32);

    printf(""Input vector:\n"");
    for (int i = 0; i < SIZE; i++) {
	vector->data.F32[i] = psRandomUniform(random);
	printf(""%f "", vector->data.F32[i]);
    }
    printf(""\n"");

    psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN);
    (void)psVectorStats(stats, vector, NULL, NULL, 0);
    printf(""Median: %f\n"", stats->sampleMedian);
   
    psVector *sorted = psVectorAlloc(SIZE, PS_TYPE_F32);
    sorted = psVectorSort(sorted, vector);

    printf(""Sorted vector:\n"");
    for (int i = 0; i < SIZE; i++) {
	printf(""%f "", sorted->data.F32[i]);
    }
    printf(""\n"");

    for (int i = 0; i < SIZE - 1; i++) {
	printf (""%d "", psCompareF32(&sorted->data.F32[i], &sorted->data.F32[i+1]));
    }
    printf(""\n"");

}"	defect	closed	high		types	unspecified	critical	fixed		
