CMP EMBEDDED.COM

Login | Register     Welcome Guest ESC Boston  esc india  Call for Abstracts
 

Listing 4: Simple math on different granularity variables Listing 4: Simple math on different granularity variables

void Test7_9(FIXED7_9 a, FIXED1_7 b)
{
FIXED7_9 temp;
printf("\nResults of operations on 7_9 and 1_7 variables\n");
temp.full = a.full + (b.full<<2);
printf("Addition result is %d.%1.1d\n", temp.part.integer,
(temp.part.fraction*10+256)/512);
if (a.full < (b.full<<2))
{
printf("a is less than b. Subtraction overflows.\n");
}
if (a.full == (b.full<<2))
{
printf("a is the same as b. Result = 0.\n");
}
if (a.full > (b.full<<2))
{
temp.full = a.full - (b.full<<2);
printf("Subtraction result is %d.%1.1d\n", temp.part.integer,
(temp.part.fraction*10+256)/512);
}
}
Embedded.com Career Center
Ready to take that job and shove it?
SEARCH JOBS

Browse all jobs

SPONSOR
RECENT JOB POSTINGS




 :