universe@601: /* universe@601: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. universe@601: * universe@601: * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. universe@601: * universe@601: * Redistribution and use in source and binary forms, with or without universe@601: * modification, are permitted provided that the following conditions are met: universe@601: * universe@601: * 1. Redistributions of source code must retain the above copyright universe@601: * notice, this list of conditions and the following disclaimer. universe@601: * universe@601: * 2. Redistributions in binary form must reproduce the above copyright universe@601: * notice, this list of conditions and the following disclaimer in the universe@601: * documentation and/or other materials provided with the distribution. universe@601: * universe@601: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" universe@601: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE universe@601: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE universe@601: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE universe@601: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR universe@601: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF universe@601: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS universe@601: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN universe@601: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) universe@601: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE universe@601: * POSSIBILITY OF SUCH DAMAGE. universe@601: */ universe@601: /** universe@601: * \file compare.h universe@601: * \brief A collection of simple compare functions. universe@601: * \author Mike Becker universe@601: * \author Olaf Wintermann universe@601: * \copyright 2-Clause BSD License universe@601: */ universe@601: universe@601: #ifndef UCX_COMPARE_H universe@601: #define UCX_COMPARE_H universe@601: universe@650: #include "common.h" universe@650: universe@601: #ifdef __cplusplus universe@601: extern "C" { universe@601: #endif universe@601: universe@601: /** universe@601: * Compares two integers of type int. universe@601: * universe@601: * @param i1 pointer to integer one universe@601: * @param i2 pointer to integer two universe@601: * @return -1, if *i1 is less than *i2, 0 if both are equal, universe@601: * 1 if *i1 is greater than *i2 universe@601: */ universe@601: int cx_cmp_int(void const *i1, void const *i2); universe@601: universe@601: /** universe@601: * Compares two integers of type long int. universe@601: * universe@601: * @param i1 pointer to long integer one universe@601: * @param i2 pointer to long integer two universe@601: * @return -1, if *i1 is less than *i2, 0 if both are equal, universe@601: * 1 if *i1 is greater than *i2 universe@601: */ universe@601: int cx_cmp_longint(void const *i1, void const *i2); universe@601: universe@601: /** universe@601: * Compares two integers of type long long. universe@601: * universe@601: * @param i1 pointer to long long one universe@601: * @param i2 pointer to long long two universe@601: * @return -1, if *i1 is less than *i2, 0 if both are equal, universe@601: * 1 if *i1 is greater than *i2 universe@601: */ universe@601: int cx_cmp_longlong(void const *i1, void const *i2); universe@601: universe@601: /** universe@601: * Compares two integers of type int16_t. universe@601: * universe@601: * @param i1 pointer to int16_t one universe@601: * @param i2 pointer to int16_t two universe@601: * @return -1, if *i1 is less than *i2, 0 if both are equal, universe@601: * 1 if *i1 is greater than *i2 universe@601: */ universe@601: int cx_cmp_int16(void const *i1, void const *i2); universe@601: universe@601: /** universe@601: * Compares two integers of type int32_t. universe@601: * universe@601: * @param i1 pointer to int32_t one universe@601: * @param i2 pointer to int32_t two universe@601: * @return -1, if *i1 is less than *i2, 0 if both are equal, universe@601: * 1 if *i1 is greater than *i2 universe@601: */ universe@601: int cx_cmp_int32(void const *i1, void const *i2); universe@601: universe@601: /** universe@601: * Compares two integers of type int64_t. universe@601: * universe@601: * @param i1 pointer to int64_t one universe@601: * @param i2 pointer to int64_t two universe@601: * @return -1, if *i1 is less than *i2, 0 if both are equal, universe@601: * 1 if *i1 is greater than *i2 universe@601: */ universe@601: int cx_cmp_int64(void const *i1, void const *i2); universe@601: universe@601: /** universe@601: * Compares two integers of type unsigned int. universe@601: * universe@601: * @param i1 pointer to unsigned integer one universe@601: * @param i2 pointer to unsigned integer two universe@601: * @return -1, if *i1 is less than *i2, 0 if both are equal, universe@601: * 1 if *i1 is greater than *i2 universe@601: */ universe@601: int cx_cmp_uint(void const *i1, void const *i2); universe@601: universe@601: /** universe@601: * Compares two integers of type unsigned long int. universe@601: * universe@601: * @param i1 pointer to unsigned long integer one universe@601: * @param i2 pointer to unsigned long integer two universe@601: * @return -1, if *i1 is less than *i2, 0 if both are equal, universe@601: * 1 if *i1 is greater than *i2 universe@601: */ universe@601: int cx_cmp_ulongint(void const *i1, void const *i2); universe@601: universe@601: /** universe@601: * Compares two integers of type unsigned long long. universe@601: * universe@601: * @param i1 pointer to unsigned long long one universe@601: * @param i2 pointer to unsigned long long two universe@601: * @return -1, if *i1 is less than *i2, 0 if both are equal, universe@601: * 1 if *i1 is greater than *i2 universe@601: */ universe@601: int cx_cmp_ulonglong(void const *i1, void const *i2); universe@601: universe@601: /** universe@601: * Compares two integers of type uint16_t. universe@601: * universe@601: * @param i1 pointer to uint16_t one universe@601: * @param i2 pointer to uint16_t two universe@601: * @return -1, if *i1 is less than *i2, 0 if both are equal, universe@601: * 1 if *i1 is greater than *i2 universe@601: */ universe@601: int cx_cmp_uint16(void const *i1, void const *i2); universe@601: universe@601: /** universe@601: * Compares two integers of type uint32_t. universe@601: * universe@601: * @param i1 pointer to uint32_t one universe@601: * @param i2 pointer to uint32_t two universe@601: * @return -1, if *i1 is less than *i2, 0 if both are equal, universe@601: * 1 if *i1 is greater than *i2 universe@601: */ universe@601: int cx_cmp_uint32(void const *i1, void const *i2); universe@601: universe@601: /** universe@601: * Compares two integers of type uint64_t. universe@601: * universe@601: * @param i1 pointer to uint64_t one universe@601: * @param i2 pointer to uint64_t two universe@601: * @return -1, if *i1 is less than *i2, 0 if both are equal, universe@601: * 1 if *i1 is greater than *i2 universe@601: */ universe@601: int cx_cmp_uint64(void const *i1, void const *i2); universe@601: universe@601: /** universe@601: * Compares two real numbers of type float with precision 1e-6f. universe@601: * universe@601: * @param f1 pointer to float one universe@601: * @param f2 pointer to float two universe@601: * @return -1, if *f1 is less than *f2, 0 if both are equal, universe@601: * 1 if *f1 is greater than *f2 universe@601: */ universe@601: universe@601: int cx_cmp_float(void const *f1, void const *f2); universe@601: universe@601: /** universe@601: * Compares two real numbers of type double with precision 1e-14. universe@601: * universe@601: * @param d1 pointer to double one universe@601: * @param d2 pointer to double two universe@601: * @return -1, if *d1 is less than *d2, 0 if both are equal, universe@601: * 1 if *d1 is greater than *d2 universe@601: */ universe@631: int cx_cmp_double( universe@631: void const *d1, universe@631: void const *d2 universe@631: ); universe@601: universe@601: /** universe@631: * Compares the integer representation of two pointers. universe@601: * universe@631: * @param ptr1 pointer to pointer one (intptr_t const*) universe@631: * @param ptr2 pointer to pointer two (intptr_t const*) universe@631: * @return -1 if *ptr1 is less than *ptr2, 0 if both are equal, universe@631: * 1 if *ptr1 is greater than *ptr2 universe@601: */ universe@631: int cx_cmp_intptr( universe@631: void const *ptr1, universe@631: void const *ptr2 universe@631: ); universe@631: universe@631: /** universe@631: * Compares the unsigned integer representation of two pointers. universe@631: * universe@631: * @param ptr1 pointer to pointer one (uintptr_t const*) universe@631: * @param ptr2 pointer to pointer two (uintptr_t const*) universe@631: * @return -1 if *ptr1 is less than *ptr2, 0 if both are equal, universe@631: * 1 if *ptr1 is greater than *ptr2 universe@631: */ universe@631: int cx_cmp_uintptr( universe@631: void const *ptr1, universe@631: void const *ptr2 universe@631: ); universe@601: universe@601: #ifdef __cplusplus universe@601: } // extern "C" universe@601: #endif universe@601: universe@601: #endif //UCX_COMPARE_H