minishell
can_add.c File Reference
#include "ft_math.h"
#include <limits.h>
#include <stdint.h>
Include dependency graph for can_add.c:

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)
 

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 }