ft_math
ft_math.h
is a remake library from original <math.h>
library.
Includes C23
, C11
and C99
functions + their float
types, can compilable and work all versions + compilers.
Setup:
Windows:
You can double click MAKE.bat
file and directly install it.
Or in console, write make
to compile the stup.
Linux, macOS:
In console, write make
to compile the setup.
PHONYS
Here's the arguments MAKE.bat
and Makefile
using:
fc
, fclean
, fclear
-> Clear both object and created products.
c
, clean
, clear
-> Clear only object files
re
-> Remake everything
Then, in console: you need to include your binary compiler library (.a file) via parameter while compiling your file.
GCC main.c mathft.a
Trigonometric functions:
Hyperbolic functions:
Exponential and Logarithmic functions:
Function Name |
Function Parameter(s) |
Description |
ft_exp ft_expf |
double x |
Computes e(2.71828) raised to the power of the given x |
ft_exp2 ft_exp2f |
double x |
Computes 2 raised to the given power x |
ft_exp10 ft_exp10f |
double x |
Calculate the exponent of 10 by x |
ft_expm1 ft_expm1f |
double x |
Computes the Euler's number raised to the given x , (-1.0 x ) |
ft_frexp ft_frexpf |
double x, int * exponent |
Returns value of mantissa, and pointed to by exponent |
ft_ilogb ft_ilogbf |
double x |
Extracts the value of the unbiased exponent from the x as int |
ft_ldexp ft_ldexpf |
double x, int exponent |
Returns x multiplied by 2 raised to the power of exponent |
ft_log ft_logf |
double x |
Calculation of the logarithm of x |
ft_log2 ft_log2f |
double x |
Calculation of the base-2 logarithm of x |
ft_log10 ft_log10f |
double x |
Calculation of the logarithm of x to the base of 10 |
ft_log1p ft_log1pf |
double x |
Calculates the logarithm of one plus of x |
ft_logb ft_logbf |
double x |
Extracts the unbiased radix-independent exponent from the x |
ft_scalbln ft_scalblnf |
double x, long int exponent |
Returns x multiplied by 2 raised to the power of exponent |
ft_scalbn ft_scalbnf |
double x, int exponent |
Returns x multiplied by 2 raised to the power of exponent |
Power functions:
Rounding and Remainder functions:
Floating-point Classification functions:
Function Name |
Function Parameter(s) |
Description |
ft_fpclassify ft_fpclassifyf |
double x |
Categorizes floating point value x into the following categories |
ft_isfinite |
double x |
Check if number is not infinity |
ft_isinf |
double x |
Check if float number is inf number (Will also return -1 if "-inf") |
ft_isnan |
double x |
Check if float number is non number |
ft_isnormal |
double x |
Check if number is normal to in use |
ft_signbit |
double x |
Checking if the float number is minus or not |
ft_significand ft_significandf |
double x |
Retrieves the fractional part of a double-precision floating-point number |
Bessel functions:
Function Name |
Function Parameter(s) |
Description |
ft_j0 ft_j0f |
double x |
Compute the Bessel function of the first kind of order zero (j0) |
ft_j1 ft_j1f |
double x |
Compute the Bessel function of the first kind of order one (j1) |
ft_jn ft_jnf |
int n, double x |
Compute the Bessel function of the first kind of order n (jn) |
ft_y0 ft_y0f |
double x |
Compute the Bessel function of the second kind of order zero (y0) |
ft_y1 ft_y1f |
double x |
Compute the Bessel function of the second kind of order one (y1) |
ft_yn ft_ynf |
int n, double x |
Compute the Bessel function of the second kind of order n (yn) |
Other functions:
Function Name |
Function Parameter(s) |
Description |
ft_erf ft_erff |
double x |
Computes the error function of the given x |
ft_erfc ft_erfcf |
double x |
Computes the complementary error of x |
ft_fibonacci |
unsigned long long number |
Every number in the sequence is the sum of two numbers preceding it in the sequence |
ft_fma ft_fmaf |
double x, double y, double z |
(x * y + z) |
ft_fabs ft_fabsf |
double x |
Get the absolute value of a x |
ft_fmax ft_fmaxf |
double x |
If (x > y ) return x , else return y |
ft_fmin ft_fminf |
double x |
If (x < y ) return x , else return y |
ft_lerp ft_lerpf |
double x, double y, double f |
Linear interpolation. |
ft_lgamma ft_lgammaf |
double x |
Computes the logarithm of the absolute x of the gamma function |
ft_modf ft_modff |
double x, double * integer |
Splits fraction an integer in float number (Returns fraction) |
ft_tgamma ft_tgammaf |
double x |
Compute the gamma function of x |
Neural Network functions:
Function Name |
Function Parameter(s) |
Description |
ft_elu ft_eluf |
double x, double aplha |
"Exponential Linear Unit" Determines the slope for negative input |
ft_leakyrelu ft_leakyreluf |
double x, double aplha |
ReLU, But has a small slope for negative values instead of a flat slope |
ft_mish ft_mishf |
double x |
Hyperbolic tangent function, and softplus is the smooth approximation |
ft_prelu ft_preluf |
double x, double aplha |
ReLU, But has a small slope for negative values instead of a flat slope |
ft_relu ft_reluf |
double x |
"The Rectified Linear Unit" Returns 0 if x is negative |
ft_sigmoid ft_sigmoidf |
double x |
Performs the role of an activation function in machine learning |
ft_softmax ft_softmaxf |
double * x, int size |
Normalizes the input array x by exponentiating each element |
ft_softmedian ft_softmedianf |
double * x, int size, double alpha |
Defined as the weighted average of the elements in a vector x |
ft_softmin ft_softminf |
double * x, int size, double alpha |
Aka: softmax(-x ) |
ft_swish ft_swishf |
double x |
Allows for a more flexible range of x |
Constants:
Trigonometric Constants:
Constants:
Environments for ft_fpclassify function:
A Few Example(s):
#include <stdio.h> /*
* int printf(char *str, ...);
*/
#include <math.h>
#include "ft_math.h"
int
main(void)
{
double x = 42;
double y = 5;
printf("Trigonometric functions:\n");
printf("[ sin(%d) = %f]\n", x, sin(x));
printf("[ft_sin(%d) = %f]\n", x, ft_sin(x));
printf("\n");
printf("[ cos(%d) = %f]\n", x, cos(x));
printf("[ft_cos(%d) = %f]\n", x, ft_cos(x));
printf("\n");
printf("[ tan(%d) = %f]\n", x, tan(x));
printf("[ft_tan(%d) = %f]\n", x, ft_tan(x));
printf("\n");
printf("[ asin(%d) = %f]\n", x, asin(x));
printf("[ft_asin(%d) = %f]\n", x, ft_asin(x));
printf("\n");
printf("[ acos(%d) = %f]\n", x, acos(x));
printf("[ft_acos(%d) = %f]\n", x, ft_acos(x));
printf("\n");
printf("[ atan(%d) = %f]\n", x, atan(x));
printf("[ft_atan(%d) = %f]\n", x, ft_atan(x));
printf("\n");
printf("[ atan2(%d, %d) = %f]\n", x, y, atan2(x, y));
printf("[ft_atan2(%d, %d) = %f]\n", x, y, ft_atan2(x, y));
printf("\n\n");
printf("[ log(%d) = %f]\n", x, log(x));
printf("[ft_log(%d) = %f]\n", x, ft_log(x));
printf("\n");
printf("[ log1p(%d) = %f]\n", x, log1p(x));
printf("[ft_log1p(%d) = %f]\n", x, ft_log1p(x));
printf("\n");
printf("[ log10(%d) = %f]\n", x, log10(x));
printf("[ft_log10(%d) = %f]\n", x, ft_log10(x));
printf("\n\n");
printf("Power functions:\n");
printf("[ pow(%d, %d) = %f]\n", x, y, pow(x, y));
printf("[ft_pow(%d, %d) = %f]\n", x, y, ft_pow(x, y));
printf("\n");
printf("[ sqrt(%d) = %f]\n", x, sqrt(x));
printf("[ft_sqrt(%d) = %f]\n", x, ft_sqrt(x));
printf("\n\n");
double nan = (0.0 / 0.0);
double inf = (1.0 / 0.0);
printf("[ isnan = %f]\n", isnan(nan));
printf("[ft_isnan = %f]\n", ft_isnan(nan));
printf("\n");
printf("[ isnan = %f]\n", isnan(-nan));
printf("[ft_isnan = %f]\n", ft_isnan(-nan));
printf("\n");
printf("[ ininf = %f]\n", isinf(inf));
printf("[ft_isinf = %f]\n", ft_isinf(inf));
printf("\n");
printf("[ ininf = %f]\n", isinf(-inf));
printf("[ft_ininf = %f]\n", ft_isinf(-inf));
printf("\n\n");
printf("Other functions:\n");
double pi = 3.1415;
double temp = 0;
printf("[ fabs(%d) = %f]\n", -x, fabs(-x));
printf("[ft_fabs(%d) = %f]\n", -x, ft_fabs(-x));
printf("\n");
printf("[ fmod(%d, %d) = %f]\n", x, y, fmod(x, y));
printf("[ft_fmod(%d, %d) = %f]\n", x, y, ft_fmod(x, y));
printf("\n");
printf("[ modf = %f] {modf(pi, &temp)}\n", modf(pi, &temp));
printf("[ modf temp = %f] {temp}\n", temp);
printf("[ ft_modf = %f] {ft_modf(pi, &temp)}\n", ft_modf(pi, &temp));
printf("[ft_modf temp = %f] {temp}\n", temp);
return (0);
}