minishell
ft_math.h File Reference
#include <stddef.h>
#include <stdbool.h>
Include dependency graph for ft_math.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool can_add (int a, int b)
 
bool can_addu (unsigned int a, unsigned int b)
 
bool can_addl (long a, long b)
 
bool can_addp (size_t a, size_t b)
 
bool can_mul (int a, int b)
 
bool can_mulu (unsigned int a, unsigned int b)
 
bool can_mull (long a, long b)
 
bool can_mulp (size_t a, size_t b)
 
int ft_min (int a, int b)
 
long ft_minl (long a, long b)
 
size_t ft_minp (size_t a, size_t b)
 
double ft_minf (double a, double b)
 
int ft_max (int a, int b)
 
long ft_maxl (long a, long b)
 
size_t ft_maxp (size_t a, size_t b)
 
double ft_maxf (double a, double b)
 

Function Documentation

◆ can_add()

bool can_add ( int  a,
int  b 
)

Definition at line 18 of file can_add.c.

19 {
20  if ((a <= 0 && 0 <= b) || (b <= 0 && 0 <= a))
21  return (true);
22  else if (0 < a)
23  return (b <= (INT_MAX - a));
24  else
25  return ((INT_MIN - a) <= b);
26 }
Here is the caller graph for this function:

◆ can_addl()

bool can_addl ( long  a,
long  b 
)

Definition at line 33 of file can_add.c.

34 {
35  if ((a <= 0 && 0 <= b) || (b <= 0 && 0 <= a))
36  return (true);
37  else if (0 < a)
38  return (b <= (LONG_MAX - a));
39  else
40  return ((LONG_MIN - a) <= b);
41 }

◆ can_addp()

bool can_addp ( size_t  a,
size_t  b 
)

Definition at line 43 of file can_add.c.

44 {
45  return (b <= (UINTPTR_MAX - a));
46 }
Here is the caller graph for this function:

◆ can_addu()

bool can_addu ( unsigned int  a,
unsigned int  b 
)

Definition at line 28 of file can_add.c.

29 {
30  return (b <= (UINT_MAX - a));
31 }

◆ can_mul()

bool can_mul ( int  a,
int  b 
)

Definition at line 18 of file can_mul.c.

19 {
20  if (a == 0 || b == 0)
21  return (true);
22  else if ((0 < a && 0 < b) || (a < 0 && b < 0))
23  return (b <= (INT_MAX / a));
24  else if (b < 0)
25  return ((INT_MIN / a) <= b);
26  else
27  return ((INT_MIN / b) <= a);
28 }
Here is the caller graph for this function:

◆ can_mull()

bool can_mull ( long  a,
long  b 
)

Definition at line 38 of file can_mul.c.

39 {
40  if (a == 0 || b == 0)
41  return (true);
42  else if ((0 < a && 0 < b) || (a < 0 && b < 0))
43  return (b <= (LONG_MAX / a));
44  else if (b < 0)
45  return ((LONG_MIN / a) <= b);
46  else
47  return ((LONG_MIN / b) <= a);
48 }

◆ can_mulp()

bool can_mulp ( size_t  a,
size_t  b 
)

Definition at line 50 of file can_mul.c.

51 {
52  if (a == 0 || b == 0)
53  return (true);
54  else
55  return (b <= (UINTPTR_MAX / a));
56 }
Here is the caller graph for this function:

◆ can_mulu()

bool can_mulu ( unsigned int  a,
unsigned int  b 
)

Definition at line 30 of file can_mul.c.

31 {
32  if (a == 0 || b == 0)
33  return (true);
34  else
35  return (b <= (UINT_MAX / a));
36 }

◆ ft_max()

int ft_max ( int  a,
int  b 
)

Definition at line 16 of file ft_max.c.

17 {
18  if (a > b)
19  return (a);
20  else
21  return (b);
22 }
Here is the caller graph for this function:

◆ ft_maxf()

double ft_maxf ( double  a,
double  b 
)

Definition at line 40 of file ft_max.c.

41 {
42  if (a > b)
43  return (a);
44  else
45  return (b);
46 }

◆ ft_maxl()

long ft_maxl ( long  a,
long  b 
)

Definition at line 24 of file ft_max.c.

25 {
26  if (a > b)
27  return (a);
28  else
29  return (b);
30 }

◆ ft_maxp()

size_t ft_maxp ( size_t  a,
size_t  b 
)

Definition at line 32 of file ft_max.c.

33 {
34  if (a > b)
35  return (a);
36  else
37  return (b);
38 }

◆ ft_min()

int ft_min ( int  a,
int  b 
)

Definition at line 16 of file ft_min.c.

17 {
18  if (a < b)
19  return (a);
20  else
21  return (b);
22 }
Here is the caller graph for this function:

◆ ft_minf()

double ft_minf ( double  a,
double  b 
)

Definition at line 40 of file ft_min.c.

41 {
42  if (a < b)
43  return (a);
44  else
45  return (b);
46 }

◆ ft_minl()

long ft_minl ( long  a,
long  b 
)

Definition at line 24 of file ft_min.c.

25 {
26  if (a < b)
27  return (a);
28  else
29  return (b);
30 }

◆ ft_minp()

size_t ft_minp ( size_t  a,
size_t  b 
)

Definition at line 32 of file ft_min.c.

33 {
34  if (a < b)
35  return (a);
36  else
37  return (b);
38 }
Here is the caller graph for this function: