mirror of
https://github.com/theoludwig/libcproject.git
synced 2025-05-21 23:21:15 +02:00
feat: add mathematics_max
, mathematics_min
Also add `mathematics_max_values` and `mathematics_min_values` to check in array.
This commit is contained in:
@ -36,3 +36,35 @@ unsigned long long mathematics_factorial(unsigned long long number) {
|
||||
int64_t mathematics_opposite(int64_t number) {
|
||||
return number * -1;
|
||||
}
|
||||
|
||||
int64_t mathematics_max(int64_t number1, int64_t number2) {
|
||||
return number1 > number2 ? number1 : number2;
|
||||
}
|
||||
|
||||
int64_t mathematics_max_values(int64_t *values, size_t values_length) {
|
||||
int64_t max = 0;
|
||||
if (values_length <= 0) {
|
||||
return max;
|
||||
}
|
||||
max = values[0];
|
||||
for (size_t index = 1; index < values_length; index++) {
|
||||
max = mathematics_max(max, values[index]);
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
int64_t mathematics_min(int64_t number1, int64_t number2) {
|
||||
return number1 > number2 ? number2 : number1;
|
||||
}
|
||||
|
||||
int64_t mathematics_min_values(int64_t *values, size_t values_length) {
|
||||
int64_t min = 0;
|
||||
if (values_length <= 0) {
|
||||
return min;
|
||||
}
|
||||
min = values[0];
|
||||
for (size_t index = 1; index < values_length; index++) {
|
||||
min = mathematics_min(min, values[index]);
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
@ -71,7 +72,54 @@ unsigned long long mathematics_factorial(unsigned long long number);
|
||||
*
|
||||
* @param number
|
||||
* @return int64_t
|
||||
*
|
||||
* @code
|
||||
* mathematics_opposite(7) // -7
|
||||
*
|
||||
* mathematics_opposite(-7) // 7
|
||||
* @endcode
|
||||
* @since vTODO
|
||||
*/
|
||||
int64_t mathematics_opposite(int64_t number);
|
||||
|
||||
/**
|
||||
* @brief Returns the largest number between 2 numbers.
|
||||
*
|
||||
* @param number1
|
||||
* @param number2
|
||||
* @return int64_t
|
||||
* @since vTODO
|
||||
*/
|
||||
int64_t mathematics_max(int64_t number1, int64_t number2);
|
||||
|
||||
/**
|
||||
* @brief Returns the largest number between multiple numbers. If the array is empty, returns 0.
|
||||
*
|
||||
* @param values
|
||||
* @param values_length
|
||||
* @return int64_t
|
||||
* @since vTODO
|
||||
*/
|
||||
int64_t mathematics_max_values(int64_t *values, size_t values_length);
|
||||
|
||||
/**
|
||||
* @brief Returns the smallest number between 2 numbers.
|
||||
*
|
||||
* @param number1
|
||||
* @param number2
|
||||
* @return int64_t
|
||||
* @since vTODO
|
||||
*/
|
||||
int64_t mathematics_min(int64_t number1, int64_t number2);
|
||||
|
||||
/**
|
||||
* @brief Returns the smallest number between multiple numbers. If the array is empty, returns 0.
|
||||
*
|
||||
* @param values
|
||||
* @param values_length
|
||||
* @return int64_t
|
||||
* @since vTODO
|
||||
*/
|
||||
int64_t mathematics_min_values(int64_t *values, size_t values_length);
|
||||
|
||||
#endif
|
||||
|
24
lib/string.h
24
lib/string.h
@ -224,6 +224,7 @@ bool string_get_is_substring(const string_t string, const string_t substring);
|
||||
* @param number
|
||||
* @param separator
|
||||
* @return string_t
|
||||
*
|
||||
* @code
|
||||
* string_get_formatted_number(1000, " ") // "1 000"
|
||||
* string_get_formatted_number(1000, ",") // "1,000"
|
||||
@ -270,7 +271,10 @@ bool string_ends_with(const string_t string, const string_t prefix);
|
||||
* @param string
|
||||
* @param substring
|
||||
* @return size_t
|
||||
* @example string_position_of("hello world", 'e') // 2
|
||||
*
|
||||
* @code
|
||||
* string_position_of("hello world", 'e') // 2
|
||||
* @endcode
|
||||
* @since v4.2.0
|
||||
*/
|
||||
size_t string_position_of(const string_t string, const char character);
|
||||
@ -281,7 +285,10 @@ size_t string_position_of(const string_t string, const char character);
|
||||
* @param string
|
||||
* @param character
|
||||
* @return size_t
|
||||
* @example string_last_position_of("hello world", 'o') // 8
|
||||
*
|
||||
* @code
|
||||
* string_last_position_of("hello world", 'o') // 8
|
||||
* @endcode
|
||||
* @since v4.2.0
|
||||
*/
|
||||
size_t string_last_position_of(const string_t string, const char character);
|
||||
@ -293,7 +300,10 @@ size_t string_last_position_of(const string_t string, const char character);
|
||||
* @param pad_string The string to pad the current string with, to the left.
|
||||
* @param target_length
|
||||
* @return string_t
|
||||
* @example string_pad_start("hello", " ", 10) // " hello"
|
||||
*
|
||||
* @code
|
||||
* string_pad_start("hello", " ", 10) // " hello"
|
||||
* @endcode
|
||||
* @since vTODO
|
||||
*/
|
||||
string_t string_pad_start(const string_t string, const string_t pad_string, size_t target_length);
|
||||
@ -304,8 +314,12 @@ string_t string_pad_start(const string_t string, const string_t pad_string, size
|
||||
* @param number
|
||||
* @param places
|
||||
* @return string_t
|
||||
* @example zero_pad(1, 2) // "01"
|
||||
* @example zero_pad(10, 2) // "10"
|
||||
*
|
||||
* @code
|
||||
* string_zero_pad(1, 2) // "01"
|
||||
*
|
||||
* string_zero_pad(10, 2) // "10"
|
||||
* @endcode
|
||||
* @since vTODO
|
||||
*/
|
||||
string_t string_zero_pad(uint64_t number, size_t places);
|
||||
|
Reference in New Issue
Block a user