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

Go to the source code of this file.

Functions

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)
 

Function Documentation

◆ 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 }