Dynamic Fraction Library 1.0.0
Reference-counted arbitrary precision rational number library (MIT OR Unlicense)
Loading...
Searching...
No Matches
Functions
Overflow Detection Helpers

Helper functions for detecting fixed-size arithmetic overflow. More...

Functions

bool di_add_overflow_int32 (int32_t a, int32_t b, int32_t *result)
 Add two int32_t values with overflow detection.
 
bool di_subtract_overflow_int32 (int32_t a, int32_t b, int32_t *result)
 Subtract two int32_t values with overflow detection.
 
bool di_multiply_overflow_int32 (int32_t a, int32_t b, int32_t *result)
 Multiply two int32_t values with overflow detection.
 
bool di_add_overflow_int64 (int64_t a, int64_t b, int64_t *result)
 Add two int64_t values with overflow detection.
 
bool di_subtract_overflow_int64 (int64_t a, int64_t b, int64_t *result)
 Subtract two int64_t values with overflow detection.
 
bool di_multiply_overflow_int64 (int64_t a, int64_t b, int64_t *result)
 Multiply two int64_t values with overflow detection.
 

Detailed Description

Helper functions for detecting fixed-size arithmetic overflow.

Function Documentation

◆ di_add_overflow_int32()

bool di_add_overflow_int32 ( int32_t  a,
int32_t  b,
int32_t *  result 
)

Add two int32_t values with overflow detection.

Parameters
aFirst operand
bSecond operand
resultPointer to store result
Returns
true if addition overflowed, false if safe
Since
1.0.0
int32_t result;
if (di_add_overflow_int32(INT32_MAX, 1, &result)) {
// Overflow occurred, use big integer arithmetic
di_int a = di_from_int32(INT32_MAX);
di_int sum = di_add(a, b);
// ... handle big integer result
}
struct di_int_internal * di_int
Integer handle for arbitrary precision integers.
di_int di_add(di_int a, di_int b)
Add two integers.
di_int di_from_int32(int32_t value)
Create a new integer from a 32-bit signed integer.
bool di_add_overflow_int32(int32_t a, int32_t b, int32_t *result)
Add two int32_t values with overflow detection.

Definition at line 1727 of file dynamic_int.h.

◆ di_add_overflow_int64()

bool di_add_overflow_int64 ( int64_t  a,
int64_t  b,
int64_t *  result 
)

Add two int64_t values with overflow detection.

Parameters
aFirst operand
bSecond operand
resultPointer to store result
Returns
true if addition overflowed, false if safe
Since
1.0.0

Definition at line 1757 of file dynamic_int.h.

◆ di_multiply_overflow_int32()

bool di_multiply_overflow_int32 ( int32_t  a,
int32_t  b,
int32_t *  result 
)

Multiply two int32_t values with overflow detection.

Parameters
aFirst operand
bSecond operand
resultPointer to store result
Returns
true if multiplication overflowed, false if safe
Since
1.0.0

Definition at line 1747 of file dynamic_int.h.

◆ di_multiply_overflow_int64()

bool di_multiply_overflow_int64 ( int64_t  a,
int64_t  b,
int64_t *  result 
)

Multiply two int64_t values with overflow detection.

Parameters
aFirst operand
bSecond operand
resultPointer to store result
Returns
true if multiplication overflowed, false if safe
Since
1.0.0

Definition at line 1775 of file dynamic_int.h.

◆ di_subtract_overflow_int32()

bool di_subtract_overflow_int32 ( int32_t  a,
int32_t  b,
int32_t *  result 
)

Subtract two int32_t values with overflow detection.

Parameters
aMinuend
bSubtrahend
resultPointer to store result
Returns
true if subtraction overflowed, false if safe
Since
1.0.0

Definition at line 1737 of file dynamic_int.h.

◆ di_subtract_overflow_int64()

bool di_subtract_overflow_int64 ( int64_t  a,
int64_t  b,
int64_t *  result 
)

Subtract two int64_t values with overflow detection.

Parameters
aMinuend
bSubtrahend
resultPointer to store result
Returns
true if subtraction overflowed, false if safe
Since
1.0.0

Definition at line 1766 of file dynamic_int.h.