⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 program2.c

📁 嵌入式系统基础课件
💻 C
字号:
/* 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 <dos.h>
#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 ;
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -