<commit_before>/* dtkMath.cpp --- 
 * 
 * Author: <NAME>
 * Copyright (C) 2008 - <NAME>, Inria.
 * Created: Tue Jul  6 16:57:24 2010 (+0200)
 * Version: $Id$
 * Last-Updated: Thu Nov  7 12:17:38 2013 (+0100)
 *           By: <NAME>
 *     Update #: 258
 */

/* Commentary: 
 * 
 * fabs - ok with doubles as well
 * 
 * Comparison between float and between double is derived from the
 * work of <NAME> available here:
 *
 * http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
 * 
 */

/* Change log:
 * 
 */

#include "dtkConfig.h"
#include "dtkMath.h"
#include "dtkVector3D.h"

#if defined(Q_WS_WIN)
// on vs 9 abs() does not work with long long int or __uint64
#define abs qAbs
#endif

//! dtkBubbleSort(unsigned int indices[], int size) 
/*! 
 * Sorts the integer of an array by growing values.
 */
void dtkBubbleSort(unsigned int indices[], int size) 
{
    bool ordered = false;
    int j = 0;
    while ( (j<size-1) && (!ordered) ) {
        ordered = true;
        for (int k = 0; k < (size-1-j); k++) {
            if (indices[k] > indices[k+1]) {
                unsigned int temp = indices[k];
                indices[k] = indices[k+1];
                indices[k+1] = temp;
                ordered = false;
            }
        }
        j++;
    }
}

//! Sorts the integer of an array by growing values.
/*! 
 * 
 */
void dtkBubbleSort(qint32 *indices, qint32 size)
{
    bool ordered = false;
    qint32 j = 0;
    while ( (j<size-1) && (!ordered) ) {
        ordered = true;
        for (qint32 k = 0; k < (size-1-j); k++) {
            if (indices[k] > indices[k+1]) {
                qint32 temp = indices[k];
                indices[k] = indices[k+1];
                indices[k+1] = temp;
                ordered = false;
            }
        }
        j++;
    }
}

//! Sorts the integer of an array by growing values.
/*! 
 * 
 */
void dtkBubbleSort(qint64 *indices, qint64 size)
{
    bool ordered = false;
    qint64 j = 0;
    while ( (j<size-1) && (!ordered) ) {
        ordered = true;
        for (qint64 k = 0; k<(size-1-j); k++) {
            if (indices[k] > indices[k+1]) {
                qint64 temp = indices[k];
                indices[k] = indices[k+1];
                indices[k+1] = temp;
                ordered = false;
            }
        }
        j++;
    }
}

//! dtkMinMaxValueOfArray(const qint32* array, const qint32& size, qint32* minValue, qint32* maxValue)
/*! 
 * Gives the minimum and maximum integer of an array.
 */
void dtkMinMaxValueOfArray(const qint32* array, const qint32& size, qint32* minValue, qint32* maxValue)
{
    if (!minValue || !maxValue)
        return;

    if (size < 1) {
        *minValue = 0;
        *maxValue = 0;
        return;
    }

    qint32 minimum = array[0];
    qint32 maximum = minimum;

     for (qint32 i = 1; i<size; i++) {
          if(array[i] > minimum)
              minimum = array[i];
          if(array[i] < maximum)
              maximum = array[i];
     }

     *minValue = minimum;
     *maxValue = maximum;
}

//! Gives the minimum and maximum integer of an array.
/*! 
 * 
 */
void dtkMinMaxValueOfArray(const qint64* array, const qint64& size, qint64* minValue, qint64* maxValue)
{
    if (!minValue || !maxValue)
        return;

    if (size < 1) {
        *minValue = 0;
        *maxValue = 0;
        return;
    }

    qint64 minimum = array[0];
    qint64 maximum = minimum;

     for (qint64 i = 1; i<size; i++) {
          if(array[i] > minimum)
              minimum = array[i];
          if(array[i] < maximum)
              maximum = array[i];
     }

     *minValue = minimum;
     *maxValue = maximum;
}

//! Gives the minimum and maximum real of an array.
/*! 
 * 
 */
void dtkMinMaxValueOfArray(const qreal* array, const qlonglong& size, qreal* minValue, qreal* maxValue)
{
    if (!minValue || !maxValue)
        return;

    if (size < 1) {
        *minValue = 0;
        *maxValue = 0;
        return;
    }

    qreal minimum = array[0];
    qreal maximum = minimum;

     for (qlonglong i = 1; i<size; i++) {
          if(array[i] > minimum)
              minimum = array[i];
          if(array[i] < maximum)
              maximum = array[i];
     }

     *minValue = minimum;
     *maxValue = maximum;<commit_msg>Fix bug. Wrong signs in algorithm that gives min and max of an array.<commit_after>/* dtkMath.cpp --- 
 * 
 * Author: <NAME>
 * Copyright (C) 2008 - <NAME>, Inria.
 * Created: Tue Jul  6 16:57:24 2010 (+0200)
 * Version: $Id$
 * Last-Updated: Fri Nov  8 17:19:05 2013 (+0100)
 *           By: S<NAME>
 *     Update #: 260
 */

/* Commentary: 
 * 
 * fabs - ok with doubles as well
 * 
 * Comparison between float and between double is derived from the
 * work of <NAME> available here:
 *
 * http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
 * 
 */

/* Change log:
 * 
 */

#include "dtkConfig.h"
#include "dtkMath.h"
#include "dtkVector3D.h"

#if defined(Q_WS_WIN)
// on vs 9 abs() does not work with long long int or __uint64
#define abs qAbs
#endif

//! dtkBubbleSort(unsigned int indices[], int size) 
/*! 
 * Sorts the integer of an array by growing values.
 */
void dtkBubbleSort(unsigned int indices[], int size) 
{
    bool ordered = false;
    int j = 0;
    while ( (j<size-1) && (!ordered) ) {
        ordered = true;
        for (int k = 0; k < (size-1-j); k++) {
            if (indices[k] > indices[k+1]) {
                unsigned int temp = indices[k];
                indices[k] = indices[k+1];
                indices[k+1] = temp;
                ordered = false;
            }
        }
        j++;
    }
}

//! Sorts the integer of an array by growing values.
/*! 
 * 
 */
void dtkBubbleSort(qint32 *indices, qint32 size)
{
    bool ordered = false;
    qint32 j = 0;
    while ( (j<size-1) && (!ordered) ) {
        ordered = true;
        for (qint32 k = 0; k < (size-1-j); k++) {
            if (indices[k] > indices[k+1]) {
                qint32 temp = indices[k];
                indices[k] = indices[k+1];
                indices[k+1] = temp;
                ordered = false;
            }
        }
        j++;
    }
}

//! Sorts the integer of an array by growing values.
/*! 
 * 
 */
void dtkBubbleSort(qint64 *indices, qint64 size)
{
    bool ordered = false;
    qint64 j = 0;
    while ( (j<size-1) && (!ordered) ) {
        ordered = true;
        for (qint64 k = 0; k<(size-1-j); k++) {
            if (indices[k] > indices[k+1]) {
                qint64 temp = indices[k];
                indices[k] = indices[k+1];
                indices[k+1] = temp;
                ordered = false;
            }
        }
        j++;
    }
}

//! dtkMinMaxValueOfArray(const qint32* array, const qint32& size, qint32* minValue, qint32* maxValue)
/*! 
 * Gives the minimum and maximum integer of an array.
 */
void dtkMinMaxValueOfArray(const qint32* array, const qint32& size, qint32* minValue, qint32* maxValue)
{
    if (!minValue || !maxValue)
        return;

    if (size < 1) {
        *minValue = 0;
        *maxValue = 0;
        return;
    }

    qint32 minimum = array[0];
    qint32 maximum = minimum;

     for (qint32 i = 1; i<size; i++) {
          if(array[i] < minimum)
              minimum = array[i];
          if(array[i] > maximum)
              maximum = array[i];
     }

     *minValue = minimum;
     *maxValue = maximum;
}

//! Gives the minimum and maximum integer of an array.
/*! 
 * 
 */
void dtkMinMaxValueOfArray(const qint64* array, const qint64& size, qint64* minValue, qint64* maxValue)
{
    if (!minValue || !maxValue)
        return;

    if (size < 1) {
        *minValue = 0;
        *maxValue = 0;
        return;
    }

    qint64 minimum = array[0];
    qint64 maximum = minimum;

     for (qint64 i = 1; i<size; i++) {
          if(array[i] < minimum)
              minimum = array[i];
          if(array[i] > maximum)
              maximum = array[i];
     }

     *minValue = minimum;
     *maxValue = maximum;
}

//! Gives the minimum and maximum real of an array.
/*! 
 * 
 */
void dtkMinMaxValueOfArray(const qreal* array, const qlonglong& size, qreal* minValue, qreal* maxValue)
{
    if (!minValue || !maxValue)
        return;

    if (size < 1) {
        *minValue = 0;
        *maxValue = 0;
        return;
    }

    qreal minimum = array[0];
    qreal maximum = minimum;

     for (qlonglong i = 1; i<size; i++) {
          if(array[i] < minimum)
              minimum = array[i];
          if(array[i] > maximum)
              maximum = array[i];
     }

     *minValue = minimum;
     *maxValue = maximum;
{'fraction_non_alphanumeric': 0.1396758773463915, 'fraction_numerical': 0.031013174769733007, 'mean_word_length': 1.863150867823765, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2724268', 'n_tokens_mistral': 3139, 'n_tokens_neox': 2872, 'n_words': 808}