/* February 25, 2002: Removed eigth term in function exp32. The value specified overflowed the representation. Found by Dr. Sridhar Narayan @ UNC Wilmington. */ #define PATCH_2_25_2002 #include #include "libepc.h" char * Fixed32ToString(FIXED32) ; char * Fixed64ToString(FIXED64) ; FIXED32 exp32(FIXED32) ; FIXED64 exp64(FIXED64) ; int main(int argc, char *argv[]) { FIXED32 e32 ; FIXED64 e64 ; enable() ; ClearScreen(0x07) ; SetCursorVisible(FALSE) ; e32 = exp32(0x00010000L) ; SetCursorPosition(10, 30) ; PutString("16.16 Fixed Pt: e = ") ; PutString(Fixed32ToString(e32)) ; SetCursorPosition(11, 30) ; PutString("Correct Result: e = 0002.B7E1") ; e64 = exp64(0x0000000100000000L) ; SetCursorPosition(13, 30) ; PutString("32.32 Fixed Pt: e = ") ; PutString(Fixed64ToString(e64)) ; SetCursorPosition(14, 30) ; PutString("Correct Result: e = 00000002.B7E15162\n") ; return 0 ; } char *Fixed32ToString(FIXED32 f) { WORD16 whole_part, fract_part ; static char result[10] ; fract_part = ((WORD16 *) &f)[0] ; whole_part = ((WORD16 *) &f)[1] ; FormatUnsigned(&result[0], whole_part, 16, 4, '0') ; result[4] = '.' ; FormatUnsigned(&result[5], fract_part, 16, 4, '0') ; return result ; } char *Fixed64ToString(FIXED64 f) { DWORD32 whole_part, fract_part ; static char result[18] ; fract_part = ((DWORD32 *) &f)[0] ; whole_part = ((DWORD32 *) &f)[1] ; FormatUnsigned(&result[0], whole_part, 16, 8, '0') ; result[8] = '.' ; FormatUnsigned(&result[9], fract_part, 16, 8, '0') ; return result ; } FIXED32 exp32(FIXED32 x) { #ifdef PATCH_2_25_2002 static FIXED32 btm[] = { 1 << 16, 2 << 16, 6 << 16, 24 << 16, 120 << 16, 720 << 16, 5040 << 16 } ; #else static FIXED32 btm[] = { 1 << 16, 2 << 16, 6 << 16, 24 << 16, 120 << 16, 720 << 16, 5040 << 16, 40320 << 16 } ; #endif static FIXED32 one_point_zero = 1 << 16 ; FIXED32 result, top ; int i ; top = result = one_point_zero ; for (i = 0; i < ENTRIES(btm); i++) { top = Product32(top, x) ; result += Quotient32(top, btm[i]) ; } return result ; } FIXED64 exp64(FIXED64 x) { /* Insert your code here */ return 0 ; }