1
1
mirror of https://github.com/theoludwig/libcproject.git synced 2024-10-05 20:16:08 +02:00
libcproject/lib/mathematics.h

125 lines
2.4 KiB
C
Raw Normal View History

#ifndef __LIBCPROJECT_MATHEMATICS__
#define __LIBCPROJECT_MATHEMATICS__
2023-01-05 19:28:05 +01:00
#define MATHEMATICS_DOUBLE_PRECISION 0.0000000001
2023-01-05 19:28:05 +01:00
#include <errno.h>
2023-01-05 19:28:05 +01:00
#include <stdbool.h>
#include <stdlib.h>
2023-01-05 19:28:05 +01:00
2023-06-25 15:07:34 +02:00
#include "types.h"
/**
* @brief Verify that 2 numbers are equal.
*
* @param number1
* @param number2
2024-09-25 14:57:34 +02:00
* @return bool
* @since v1.0.0
*/
bool mathematics_equals(const float64_t number1, const float64_t number2);
2023-01-05 19:28:05 +01:00
/**
* @brief Get the absolute value of a number.
*
* @param number
* @return uint64_t
* @since v1.0.0
*/
uint64_t mathematics_absolute_value(const int64_t number);
2023-01-05 19:28:05 +01:00
/**
* @brief Calculates the power of a number.
*
* @param base
* @param exponent
* @return uint64_t
* @since v1.0.0
*/
uint64_t mathematics_pow(uint64_t base, uint64_t exponent);
2023-01-05 19:28:05 +01:00
/**
2023-08-09 21:08:15 +02:00
* @brief Calculates the nth root of a number.
2023-01-05 19:28:05 +01:00
*
* @param number
* @param nth_root
* @return float64_t
* @since v1.0.0
2023-01-05 19:28:05 +01:00
*/
float64_t mathematics_root(float64_t number, uint64_t nth_root);
2023-01-05 19:28:05 +01:00
/**
* @brief Calculates the square root of a number using Heron's method.
*
* @param number
* @return float64_t
* @since v1.0.0
*/
float64_t mathematics_square_root(float64_t number);
2023-01-05 19:28:05 +01:00
/**
* @brief Calculates the factorial of a number.
*
* @param number
* @return uint64_t
* @since v1.0.0
*/
uint64_t mathematics_factorial(uint64_t number);
2023-01-05 19:28:05 +01:00
2024-09-13 14:44:26 +02:00
/**
* @brief Calulcates the opposite number (additive inverse).
*
* @param number
* @return int64_t
*
* @code
* mathematics_opposite(7) // -7
*
* mathematics_opposite(-7) // 7
* @endcode
2024-09-15 18:43:39 +02:00
* @since v4.3.0
2024-09-13 14:44:26 +02:00
*/
int64_t mathematics_opposite(int64_t number);
/**
* @brief Returns the largest number between 2 numbers.
*
* @param number1
* @param number2
* @return int64_t
2024-09-15 18:43:39 +02:00
* @since v4.3.0
*/
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
2024-09-15 18:43:39 +02:00
* @since v4.3.0
*/
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
2024-09-15 18:43:39 +02:00
* @since v4.3.0
*/
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
2024-09-15 18:43:39 +02:00
* @since v4.3.0
*/
int64_t mathematics_min_values(int64_t *values, size_t values_length);
2023-01-05 19:28:05 +01:00
#endif