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

📄 ieeefloat.c

📁 mp3编码库
💻 C
字号:
/* Copyright (C) 1988-1991 Apple Computer, Inc. * All Rights Reserved. * * Warranty Information * Even though Apple has reviewed this software, Apple makes no warranty * or representation, either express or implied, with respect to this * software, its quality, accuracy, merchantability, or fitness for a  * particular purpose.  As a result, this software is provided "as is," * and you, its user, are assuming the entire risk as to its quality * and accuracy. * * This code may be used and freely distributed as long as it includes * this copyright notice and the warranty information. * * Machine-independent I/O routines for IEEE floating-point numbers. * * NaN's and infinities are converted to HUGE_VAL or HUGE, which * happens to be infinity on IEEE machines.  Unfortunately, it is * impossible to preserve NaN's in a machine-independent way. * Infinities are, however, preserved on IEEE machines. * * These routines have been tested on the following machines: *	Apple Macintosh, MPW 3.1 C compiler *	Apple Macintosh, THINK C compiler *	Silicon Graphics IRIS, MIPS compiler *	Cray X/MP and Y/MP *	Digital Equipment VAX *	Sequent Balance (Multiprocesor 386) *	NeXT * * * Implemented by Malcolm Slaney and Ken Turkowski. * * Malcolm Slaney contributions during 1988-1990 include big- and little- * endian file I/O, conversion to and from Motorola's extended 80-bit * floating-point format, and conversions to and from IEEE single- * precision floating-point format. * * In 1991, Ken Turkowski implemented the conversions to and from * IEEE double-precision format, added more precision to the extended * conversions, and accommodated conversions involving +/- infinity, * NaN's, and denormalized numbers. * * $Id: ieeefloat.c,v 1.1 1993/06/11 17:45:46 malcolm Exp $ * * $Log: ieeefloat.c,v $ * Revision 1.1  1993/06/11  17:45:46  malcolm * Initial revision * */#include	<stdio.h>#include	<math.h>
#include	"./libmp3enc/libmp3enc.h"#include	"ieeefloat.h"/**************************************************************** * The following two routines make up for deficiencies in many * compilers to convert properly between unsigned integers and * floating-point.  Some compilers which have this bug are the * THINK_C compiler for the Macintosh and the C compiler for the * Silicon Graphics MIPS-based Iris. ****************************************************************/#ifdef applec	/* The Apple C compiler works */# define FloatToUnsigned(f)	((u32)(f))# define UnsignedToFloat(u)	((defdouble)(u))#else /* applec */# define FloatToUnsigned(f)	((u32)(((i32)((f) - 2147483648.0)) + 2147483647L + 1))# define UnsignedToFloat(u)	(((defdouble)((i32)((u) - 2147483647L - 1))) + 2147483648.0)#endif /* applec *//**************************************************************** * Single precision IEEE floating-point conversion routines ****************************************************************/#define SEXP_MAX		255#define SEXP_OFFSET		127#define SEXP_SIZE		8#define SEXP_POSITION	(32-SEXP_SIZE-1)/**************************************************************** * Extended precision IEEE floating-point conversion routines ****************************************************************/defdoubleConvertFromIeeeExtended(bytes)i8* bytes;{	defdouble	f;	i32	expon;	u32 hiMant, loMant;#ifdef	TEST	printf("ConvertFromIEEEExtended(%lx,%lx,%lx,%lx,%lx,%lx,%lx,%lx,%lx,%lx\r",	(i32)bytes[0], (i32)bytes[1], (i32)bytes[2], (i32)bytes[3], 	(i32)bytes[4], (i32)bytes[5], (i32)bytes[6], 	(i32)bytes[7], (i32)bytes[8], (i32)bytes[9]);#endif		expon = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF);	hiMant	=	((u32)(bytes[2] & 0xFF) << 24)			|	((u32)(bytes[3] & 0xFF) << 16)			|	((u32)(bytes[4] & 0xFF) << 8)			|	((u32)(bytes[5] & 0xFF));	loMant	=	((u32)(bytes[6] & 0xFF) << 24)			|	((u32)(bytes[7] & 0xFF) << 16)			|	((u32)(bytes[8] & 0xFF) << 8)			|	((u32)(bytes[9] & 0xFF));	if (expon == 0 && hiMant == 0 && loMant == 0) {		f = 0;	}	else {		if (expon == 0x7FFF) {	/* Infinity or NaN */			f = HUGE_VAL;		}
#ifdef WIN32		else {
			printf("hi, i'm here\n");			expon -= 16383;			f  = ldexp(UnsignedToFloat(hiMant), expon-=31);			f += ldexp(UnsignedToFloat(loMant), expon-=32);		}
#endif	}	if (bytes[0] & 0x80)		return -f;	else		return f;}

⌨️ 快捷键说明

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