portable multiplication that can produce 64-bit products More...


Functions | |
| CGUL_BEGIN_C CGUL_EXPORT void | cgul_multiply64 (cgul_exception_t *cex, unsigned int x, unsigned int y, unsigned int *high, unsigned int *low) |
Portable multiplication that can produce 64-bit products.
| CGUL_BEGIN_C CGUL_EXPORT void cgul_multiply64 | ( | cgul_exception_t * | cex, |
| unsigned int | x, | ||
| unsigned int | y, | ||
| unsigned int * | high, | ||
| unsigned int * | low | ||
| ) |
This function multiplies two 32-bit unsigned integers x and y to produce a 64-bit unsigned product using only 32-bit arithmetic. The high 32-bits of the 64-bit product will be stored in *high if high is not NULL, and the low 32-bits of the 64-bit product will be stored in *low if low is not NULL.
The following printf() format specification can be used to convert *high and *low into a proper hexadecimal string because it accounts for the significance of the leading zeros in *low:
printf("%#0x%08x", *high, *low);
This function takes about 2.5 times as long to run as native 64-bit multiplication. Thus, it should only be used if your compiler does not support a 64-bit type. To conditionally use this code, include the "cgul_int.h" header and test if CGUL_UINT64 is not defined.
| [in] | cex | c-style exception |
| [in] | x | first 32-bit multiplicand |
| [in] | y | second 32-bit multiplicand |
| [out] | high | high 32-bits of the product of x and y |
| [out] | low | low 32-bits of the product of x and y |
Referenced by cgul_multiply64_cxx::multiply64().