75 #define WS_IEEE754_SINGLE_EXP_SIZE  8    76 #define WS_IEEE754_SINGLE_MANT_SIZE 23    77 #define WS_IEEE754_SINGLE_BIAS      127    79 #define WS_IEEE754_SINGLE_EXP_MIN   -126    80 #define WS_IEEE754_SINGLE_EXP_MAX   127    82 #define WS_IEEE754_POSITIVE_INFINITY    0x7f800000   162     if (value * 2.0 > 1.0) {
   164         if (mant == 0x800000) {
   190     buf[3] = (mant & 0x000000ff);
   191     buf[2] = (mant & 0x0000ff00) >> 8;
   192     buf[1] = (mant & 0x00ff0000) >> 16;
   193     buf[0] = (mant & 0xff000000) >> 24;
   200                                          double *value_return)
   250     *value_return = value;
   258     return (buf[0] & 0x80) >> 7;
   267     value |= (buf[1] & 0x80) >> 7;
   289 void ws_ieee754_print(
unsigned char *buf)
   293     for (i = 0; i < 4; i++) {
   294         unsigned char mask = 0x80;
   295         unsigned char ch = buf[i];
   297         for (j = 0; j < 8; j++) {
   303             if ((i == 0 && j == 0)
   304                 || (i == 1 && j == 0))
   315 #include <machine/ieee.h>   317 void check_value(
double num)
   320     unsigned char buf[4];
   321     struct ieee_single *s = (
struct ieee_single *) & native;
   322     unsigned int *uip = (
unsigned int *) s;
   323     unsigned int n = ntohl(*uip);
   327     if (memcmp(buf, &n, 4) != 0) {
   329         printf(
"%f failed:\n", num);
   331         ws_ieee754_print(buf);
   333         ws_ieee754_print((
unsigned char *) &n);
   339         printf(
"\ndecode of %f failed: got %f\n", num, d);
   345 int main(
int argc, 
char *argv[])
   347     unsigned char buf[4];
   348     unsigned int rounds = 0;
   353         for (i = 1; i < argc; i++)
   354             check_value(strtod(argv[1], NULL));
   360     ws_ieee754_print(buf);
   364     ws_ieee754_print(buf);
   365     check_value(340282346638528859811704183484516925440.0);
   368     ws_ieee754_print(buf);
   369     check_value( -340282346638528859811704183484516925440.0);
   372     ws_ieee754_print(buf);
   373     check_value(3.0 * pow(2, -129));
   376     ws_ieee754_print(buf);
   377     check_value(pow(2, -149));
   380     ws_ieee754_print(buf);
   381     check_value(pow(2, -149) * .1);
   384     ws_ieee754_print(buf);
   385     check_value( -pow(2, -149));
   388     ws_ieee754_print(buf);
   400         if ((++rounds % 100000) == 0) {
   401             printf(
"%d ", rounds);
 unsigned char ws_ieee754_nan[4]
#define WS_IEEE754_SINGLE_BIAS
WsIeee754Result ws_ieee754_decode_single(unsigned char *buf, double *value_return)
gw_assert(wtls_machine->packet_to_send !=NULL)
WsUInt32 ws_ieee754_single_get_exp(unsigned char *buf)
WsUInt32 ws_ieee754_single_get_mant(unsigned char *buf)
WsUInt32 ws_ieee754_single_get_sign(unsigned char *buf)
WsIeee754Result ws_ieee754_encode_single(double value, unsigned char *buf)
unsigned char ws_ieee754_positive_inf[4]
#define WS_IEEE754_SINGLE_MANT_SIZE
int main(int argc, char **argv)
#define WS_IEEE754_SINGLE_EXP_MIN
#define WS_IEEE754_SINGLE_EXP_MAX
unsigned char ws_ieee754_negative_inf[4]