Syntax, Example, Muldiv24s( ) function – Echelon Neuron C User Manual
Page 136
116
Functions
always use muldiv24() without loss of precision, compared to muldiv(), if neither
A nor B ever exceeds 256.
Syntax
#include
unsigned long muldiv24 (unsigned long
A
, unsigned int
B
,
unsigned int
C
);
Example
#include
unsigned long a, d;
unsigned int b, c;
...
void f(void)
{
d = muldiv24(a, b, c); // d = (a*b)/c
}
muldiv24s( )
Function
The muldiv24s( ) function permits the computation of (
A
*
B
)/
C
where
A
is a 16-bit
value, and
B
and
C
are both 8-bit values, but the intermediate product of (
A
*
B
) is
a 24-bit value. Thus, the performance of the function is improved while
maintaining the accuracy of the result. There are two versions of this function:
muldiv24s( ) and muldiv24( ). The muldiv24s( ) function uses signed arithmetic,
while the muldiv24( ) function (see above) uses unsigned arithmetic.
See also muldiv( ) and muldivs( ) for functions which use 32-bit intermediate
accuracy for greater accuracy at the expense of slower performance. You can
always use muldiv24s() without loss of precision, compared to muldivs(), if either
A or B always is in the -128..+127 value interval.
Syntax
#include
signed long muldiv24s (signed long
A
, signed int
B
, signed int
C
);
Example
#include
signed long a, d;
signed int b, c;
...
void f(void)
{
d = muldiv24s(a, b, c); // d = (a*b)/c
}