Skip to content
Snippets Groups Projects
Commit f18a1134 authored by Gary E. Miller's avatar Gary E. Miller :speech_balloon:
Browse files

ieee754io: remove now pointless, and broken, standalone shim.

No need with working tests.
parent 521c7270
No related branches found
No related tags found
No related merge requests found
......@@ -376,182 +376,6 @@ fetch_ieee754(
}
}
#if defined(DEBUG) && defined(DEBUG_PARSELIB)
#include <stdlib.h>
static int
put_ieee754(
unsigned char **bufpp,
int size,
l_fp *lfpp,
offsets_t offsets
)
{
l_fp outlfp;
#ifdef DEBUG_PARSELIB
unsigned int sign;
unsigned int bias;
#endif
/*unsigned int maxexp;*/
int mbits;
int msb;
unsigned long mantissa_low = 0;
unsigned long mantissa_high = 0;
#ifdef DEBUG_PARSELIB
unsigned long characteristic = 0;
long exponent;
#endif
/*int length;*/
unsigned long mask;
UNUSED_ARG(bufpp);
UNUSED_ARG(offsets);
outlfp = *lfpp;
switch (size)
{
case IEEE_DOUBLE:
/*length = 8;*/
mbits = 52;
#ifdef DEBUG_PARSELIB
bias = 1023;
#endif
/*maxexp = 2047;*/
break;
case IEEE_SINGLE:
/*length = 4;*/
mbits = 23;
#ifdef DEBUG_PARSELIB
bias = 127;
#endif
/*maxexp = 255;*/
break;
default:
return IEEE_BADCALL;
}
/*
* find sign
*/
if (L_ISNEG(outlfp))
{
L_NEG(outlfp);
#ifdef DEBUG_PARSELIB
sign = 1;
#endif
}
else
{
#ifdef DEBUG_PARSELIB
sign = 0;
#endif
}
if (outlfp == 0)
{
#ifdef DEBUG_PARSELIB
exponent = mantissa_high = mantissa_low = 0; /* true zero */
#endif
}
else
{
/*
* find number of significant integer bits
*/
mask = 0x80000000;
if (lfpuint(outlfp))
{
msb = 63;
while (mask && ((lfpuint(outlfp) & mask) == 0))
{
mask >>= 1;
msb--;
}
}
else
{
msb = 31;
while (mask && ((lfpfrac(outlfp) & mask) == 0))
{
mask >>= 1;
msb--;
}
}
switch (size)
{
case IEEE_SINGLE:
mantissa_high = 0;
if (msb >= 32)
{
mantissa_low = (lfpuint(outlfp) & ((1 << (msb - 32)) - 1)) << (mbits - (msb - 32));
mantissa_low |= lfpfrac(outlfp) >> (mbits - (msb - 32));
}
else
{
mantissa_low = (lfpfrac(outlfp) << (mbits - msb)) & ((1 << mbits) - 1);
}
break;
case IEEE_DOUBLE:
if (msb >= 32)
{
mantissa_high = (lfpuint(outlfp) << (mbits - msb)) & ((1 << (mbits - 32)) - 1);
mantissa_high |= lfpfrac(outlfp) >> (32 - (mbits - msb));
mantissa_low = (lfpuint(outlfp) & ((1 << (msb - mbits)) - 1)) << (32 - (msb - mbits));
/* coverity[negative_shift] */
mantissa_low |= lfpfrac(outlfp) >> (msb - mbits);
}
else
{
mantissa_high = lfpfrac(outlfp) << (mbits - 32 - msb);
mantissa_low = lfpfrac(outlfp) << (mbits - 32);
}
}
#ifdef DEBUG_PARSELIB
exponent = msb - 32;
characteristic = exponent + bias;
if (debug > 4)
printf("FP: %s\n", fmt_flt(sign, mantissa_high, mantissa_low, characteristic));
#endif
}
return IEEE_OK;
}
int main(
int argc,
char **argv
)
{
static offsets_t native_off = { 0, 1, 2, 3, 4, 5, 6, 7 };
double f = 1.0;
double *f_p = &f;
l_fp fp;
if (argc == 2)
{
if (sscanf(argv[1], "%lf", &f) != 1)
{
printf("cannot convert %s to a float\n", argv[1]);
return EXIT_FAILURE;
}
}
printf("double: %s %s\n", fmt_blong(*(unsigned long *)&f, 32), fmt_blong(*(unsigned long *)((char *)(&f)+4), 32));
printf("fetch from %f = %d\n", f, fetch_ieee754((void *)&f_p, IEEE_DOUBLE, &fp, native_off));
printf("fp [%s %s] = %s\n", fmt_blong(lfpuint(fp), 32), fmt_blong(lfpfrac(fp), 32), mfptoa(lfpuint(fp), lfpfrac(fp), 15));
f_p = &f;
put_ieee754((void *)&f_p, IEEE_DOUBLE, &fp, native_off);
return EXIT_SUCCESS;
}
#endif
/*
* History:
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment