- bug fixes and improvements

This commit is contained in:
zolliker
2011-03-25 14:28:45 +00:00
parent ccae9f0d16
commit 1384d9034a
12 changed files with 366 additions and 242 deletions

View File

@@ -3,6 +3,7 @@
#include "ascon.h"
#include "ascon.i"
#include "dynstring.h"
#include "cnvrt.h"
/*
* this is a (scriptcontext) general binary protocol driver
@@ -64,65 +65,6 @@ typedef struct {
int dumpFrom;
} BinPrivate;
/*-------------------------------------------------------------------------*/
static void double2ieee(double input, char ieee[4])
{
/* convert double to IEEE 32 bit floating number (denormalized numbers are considered as zero) */
long mantissa;
int exponent;
if (input == 0) {
ieee[0] = 0;
ieee[1] = 0;
ieee[2] = 0;
ieee[3] = 0;
} else {
mantissa = 0x1000000 * (frexp(fabs(input), &exponent));
exponent = exponent - 1 + 127;
if (exponent < 0) {
exponent = 0;
} else if (exponent > 0xFE) {
exponent = 0xFE;
}
if (input < 0) {
ieee[0] = 0x80 | (exponent >> 1);
} else {
ieee[0] = exponent >> 1;
}
ieee[1] = (exponent & 1) << 7 | ((mantissa & 0x7F0000) >> 16);
ieee[2] = (mantissa & 0xFF00) >> 8;
ieee[3] = mantissa & 0xFF;
}
return;
}
/*-------------------------------------------------------------------------*/
static double ieee2double(char ieee[4])
{
/* IEEE 32 bit floating number to double (denormalized numbers are considered as zero) */
long mantissa;
double output;
int exponent;
mantissa = ((ieee[1] << 16) & 0x7FFFFF)
| ((ieee[2] << 8) & 0xFF00)
| ((ieee[3]) & 0xFF);
exponent = (ieee[0] & 0x7F) * 2 + ((ieee[1] >> 7) & 1); /* raw exponent */
if (exponent == 0 && mantissa == 0) {
return 0.0;
}
output = ldexp(mantissa, -23) + 1.0;
if (ieee[0] & 0x80) {
output = -output;
}
return output * ldexp(1, exponent - 127);
}
/*----------------------------------------------------------------------------*/
static int calc_crc(char *inp, int inpLen)
{