TA的每日心情 | 奋斗 2021-9-6 20:56 |
---|
签到天数: 327 天 [LV.8]以坛为家I
|
发表于 2012-9-24 16:34:08
|
显示全部楼层
dorothyorsusie 发表于 2012-9-24 10:34
能不能贴出来看看,怎么写的
static void ibm_to_float(int from[], int to[], int n, int endian)
/***********************************************************************
ibm_to_float - convert between 32 bit IBM and IEEE floating numbers
************************************************************************
Input::
from input vector
to output vector, can be same as input vector
endian byte order =0 little endian (DEC, PC's)
=1 other systems
*************************************************************************
Notes:
Up to 3 bits lost on IEEE -> IBM
Assumes sizeof(int) == 4
IBM -> IEEE may overflow or underflow, taken care of by
substituting large number or zero
Only integer shifting and masking are used.
*************************************************************************
Credits: CWP: Brian Sumner, c.1985
*************************************************************************/
{
register int fconv, fmant, i, t;
for (i = 0;i < n; ++i) {
fconv = from;
/* if little endian, i.e. endian=0 do this */
if (endian == 0) fconv = (fconv << 24) | ((fconv >> 24) & 0xff) |
((fconv & 0xff00) << 8) | ((fconv & 0xff0000) >> 8);
if (fconv) {
fmant = 0x00ffffff & fconv;
/* The next two lines were added by Toralf Foerster */
/* to trap non-IBM format data i.e. conv=0 data */
if (fmant == 0)
warn("mantissa is zero data may not be in IBM FLOAT Format !");
t = (int) ((0x7f000000 & fconv) >> 22) - 130;
while (!(fmant & 0x00800000)) { --t; fmant <<= 1; }
if (t > 254) fconv = (0x80000000 & fconv) | 0x7f7fffff;
else if (t <= 0) fconv = 0;
else fconv = (0x80000000 & fconv) | (t << 23)
| (0x007fffff & fmant);
}
to = fconv;
}
return;
} |
评分
-
查看全部评分
|