mirror of
https://github.com/theoludwig/libcproject.git
synced 2024-12-11 21:13:00 +01:00
Compare commits
No commits in common. "2fd8d102e9b94416c9b754f6e9b6c85efa294c72" and "c49d5f5421c7444e547cab03a111cc8726b2c555" have entirely different histories.
2fd8d102e9
...
c49d5f5421
@ -32,39 +32,3 @@ float mathematics_square_root(float number) {
|
|||||||
unsigned long long mathematics_factorial(unsigned long long number) {
|
unsigned long long mathematics_factorial(unsigned long long number) {
|
||||||
return number == 0 ? 1 : number * mathematics_factorial(number - 1);
|
return number == 0 ? 1 : number * mathematics_factorial(number - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
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,7 +5,6 @@
|
|||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
@ -67,59 +66,4 @@ float mathematics_square_root(float number);
|
|||||||
*/
|
*/
|
||||||
unsigned long long mathematics_factorial(unsigned long long number);
|
unsigned long long mathematics_factorial(unsigned long long number);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Calulcates the opposite number (additive inverse).
|
|
||||||
*
|
|
||||||
* @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
|
#endif
|
||||||
|
24
lib/string.h
24
lib/string.h
@ -224,7 +224,6 @@ bool string_get_is_substring(const string_t string, const string_t substring);
|
|||||||
* @param number
|
* @param number
|
||||||
* @param separator
|
* @param separator
|
||||||
* @return string_t
|
* @return string_t
|
||||||
*
|
|
||||||
* @code
|
* @code
|
||||||
* string_get_formatted_number(1000, " ") // "1 000"
|
* string_get_formatted_number(1000, " ") // "1 000"
|
||||||
* string_get_formatted_number(1000, ",") // "1,000"
|
* string_get_formatted_number(1000, ",") // "1,000"
|
||||||
@ -271,10 +270,7 @@ bool string_ends_with(const string_t string, const string_t prefix);
|
|||||||
* @param string
|
* @param string
|
||||||
* @param substring
|
* @param substring
|
||||||
* @return size_t
|
* @return size_t
|
||||||
*
|
* @example string_position_of("hello world", 'e') // 2
|
||||||
* @code
|
|
||||||
* string_position_of("hello world", 'e') // 2
|
|
||||||
* @endcode
|
|
||||||
* @since v4.2.0
|
* @since v4.2.0
|
||||||
*/
|
*/
|
||||||
size_t string_position_of(const string_t string, const char character);
|
size_t string_position_of(const string_t string, const char character);
|
||||||
@ -285,10 +281,7 @@ size_t string_position_of(const string_t string, const char character);
|
|||||||
* @param string
|
* @param string
|
||||||
* @param character
|
* @param character
|
||||||
* @return size_t
|
* @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
|
* @since v4.2.0
|
||||||
*/
|
*/
|
||||||
size_t string_last_position_of(const string_t string, const char character);
|
size_t string_last_position_of(const string_t string, const char character);
|
||||||
@ -300,10 +293,7 @@ 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 pad_string The string to pad the current string with, to the left.
|
||||||
* @param target_length
|
* @param target_length
|
||||||
* @return string_t
|
* @return string_t
|
||||||
*
|
* @example string_pad_start("hello", " ", 10) // " hello"
|
||||||
* @code
|
|
||||||
* string_pad_start("hello", " ", 10) // " hello"
|
|
||||||
* @endcode
|
|
||||||
* @since vTODO
|
* @since vTODO
|
||||||
*/
|
*/
|
||||||
string_t string_pad_start(const string_t string, const string_t pad_string, size_t target_length);
|
string_t string_pad_start(const string_t string, const string_t pad_string, size_t target_length);
|
||||||
@ -314,12 +304,8 @@ string_t string_pad_start(const string_t string, const string_t pad_string, size
|
|||||||
* @param number
|
* @param number
|
||||||
* @param places
|
* @param places
|
||||||
* @return string_t
|
* @return string_t
|
||||||
*
|
* @example zero_pad(1, 2) // "01"
|
||||||
* @code
|
* @example zero_pad(10, 2) // "10"
|
||||||
* string_zero_pad(1, 2) // "01"
|
|
||||||
*
|
|
||||||
* string_zero_pad(10, 2) // "10"
|
|
||||||
* @endcode
|
|
||||||
* @since vTODO
|
* @since vTODO
|
||||||
*/
|
*/
|
||||||
string_t string_zero_pad(uint64_t number, size_t places);
|
string_t string_zero_pad(uint64_t number, size_t places);
|
||||||
|
@ -6,11 +6,6 @@ void mathematics_test() {
|
|||||||
mathematics_root_test();
|
mathematics_root_test();
|
||||||
mathematics_square_root_test();
|
mathematics_square_root_test();
|
||||||
mathematics_factorial_test();
|
mathematics_factorial_test();
|
||||||
mathematics_opposite_test();
|
|
||||||
mathematics_max_test();
|
|
||||||
mathematics_max_values_test();
|
|
||||||
mathematics_min_test();
|
|
||||||
mathematics_min_values_test();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void mathematics_absolute_value_test() {
|
void mathematics_absolute_value_test() {
|
||||||
@ -61,38 +56,3 @@ void mathematics_factorial_test() {
|
|||||||
assert(mathematics_factorial(9) == 362880);
|
assert(mathematics_factorial(9) == 362880);
|
||||||
assert(mathematics_factorial(10) == 3628800);
|
assert(mathematics_factorial(10) == 3628800);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mathematics_opposite_test() {
|
|
||||||
assert(mathematics_opposite(-7) == 7);
|
|
||||||
assert(mathematics_opposite(7) == -7);
|
|
||||||
}
|
|
||||||
|
|
||||||
void mathematics_max_test() {
|
|
||||||
assert(mathematics_max(0, 0) == 0);
|
|
||||||
assert(mathematics_max(0, 1) == 1);
|
|
||||||
assert(mathematics_max(2, 0) == 2);
|
|
||||||
assert(mathematics_max(54, 37) == 54);
|
|
||||||
}
|
|
||||||
|
|
||||||
void mathematics_max_values_test() {
|
|
||||||
int64_t values[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
|
||||||
assert(mathematics_max_values(values, 10) == 9);
|
|
||||||
|
|
||||||
int64_t values2[] = {8, 6, 4, 7};
|
|
||||||
assert(mathematics_max_values(values2, 4) == 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
void mathematics_min_test() {
|
|
||||||
assert(mathematics_min(0, 0) == 0);
|
|
||||||
assert(mathematics_min(3, 5) == 3);
|
|
||||||
assert(mathematics_min(2, 1) == 1);
|
|
||||||
assert(mathematics_min(54, 37) == 37);
|
|
||||||
}
|
|
||||||
|
|
||||||
void mathematics_min_values_test() {
|
|
||||||
int64_t values[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
|
||||||
assert(mathematics_min_values(values, 10) == 0);
|
|
||||||
|
|
||||||
int64_t values2[] = {9, 6, 8, 7};
|
|
||||||
assert(mathematics_min_values(values2, 4) == 6);
|
|
||||||
}
|
|
||||||
|
@ -17,14 +17,4 @@ void mathematics_square_root_test();
|
|||||||
|
|
||||||
void mathematics_factorial_test();
|
void mathematics_factorial_test();
|
||||||
|
|
||||||
void mathematics_opposite_test();
|
|
||||||
|
|
||||||
void mathematics_max_test();
|
|
||||||
|
|
||||||
void mathematics_max_values_test();
|
|
||||||
|
|
||||||
void mathematics_min_test();
|
|
||||||
|
|
||||||
void mathematics_min_values_test();
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user