Index: ossp-pkg/xds/Makefile.in RCS File: /v/ossp/cvs/ossp-pkg/xds/Makefile.in,v rcsdiff -q -kk '-r1.33' '-r1.34' -u '/v/ossp/cvs/ossp-pkg/xds/Makefile.in,v' 2>/dev/null --- Makefile.in 2001/08/22 20:22:18 1.33 +++ Makefile.in 2001/08/23 08:42:49 1.34 @@ -53,7 +53,7 @@ # list of objects LIB_NAME = libxds.la -LIB_OBJS = xds.lo xds_engine_xdr.lo xds_engine_xml.lo float2xds-float.lo +LIB_OBJS = xds.lo xds_engine_xdr.lo xds_engine_xml.lo TST_SRCS = xds_test_lib.c xds_test_xdr.c xds_test_xml.c # file containing the official version information Index: ossp-pkg/xds/float2xds-float.c RCS File: /v/ossp/cvs/ossp-pkg/xds/Attic/float2xds-float.c,v co -q -kk -p'1.2' '/v/ossp/cvs/ossp-pkg/xds/Attic/float2xds-float.c,v' | diff -u /dev/null - -L'ossp-pkg/xds/float2xds-float.c' 2>/dev/null --- ossp-pkg/xds/float2xds-float.c +++ - 2024-05-16 06:54:39.505983874 +0200 @@ -0,0 +1,71 @@ +#include "xds_p.h" + +int float2xds_float(xds_float_t* new_num, float num) + { + const static unsigned int base = 2; + size_t i; + float tmp; + + /* Handle zero as a special case. */ + + if (num == 0.0) + { + new_num->sign = 0; + new_num->fraction = 0; + new_num->exponent = -127; + return 0; + } + + /* Determine the sign of the number. */ + + if (num < 0) + { + new_num->sign = 1; + num = 0 - num; + } + else + new_num->sign = 0; + + /* Canonify the number before we convert it. */ + + new_num->exponent = 0; + while (num < 1) + { + num *= base; + --new_num->exponent; + } + + /* Find the exponent. */ + + for (i = 0, tmp = 1; i <= 128; ++i, tmp *= base) + { + if (tmp*base > num) + break; + } + if (i <= 128) + { + num = num / tmp - 1; + new_num->exponent += i; + } + else + return 1; + + /* Calculate the fraction part. */ + + for (new_num->fraction = 0, i = 0; i < 23; ++i) + { + new_num->fraction *= base; + if (num >= 1.0 / base) + { + new_num->fraction |= 1; + num = num * base - 1; + } + else + { + new_num->fraction |= 0; + num *= base; + } + } + + return 0; + } Index: ossp-pkg/xds/xds.h.in RCS File: /v/ossp/cvs/ossp-pkg/xds/xds.h.in,v rcsdiff -q -kk '-r1.15' '-r1.16' -u '/v/ossp/cvs/ossp-pkg/xds/xds.h.in,v' 2>/dev/null --- xds.h.in 2001/08/22 20:19:50 1.15 +++ xds.h.in 2001/08/23 08:42:50 1.16 @@ -159,14 +159,4 @@ xds_declare_formatting_engine(xml_encode_string); xds_declare_formatting_engine(xml_decode_string); -typedef struct - { - unsigned int sign :1; - unsigned int fraction :23; - int exponent :8; - } -xds_float_t; - -int float2xds_float(xds_float_t* new_num, float num); - #endif /* __XDS_H__ */ Index: ossp-pkg/xds/xds_engine_xdr.c RCS File: /v/ossp/cvs/ossp-pkg/xds/xds_engine_xdr.c,v rcsdiff -q -kk '-r1.7' '-r1.8' -u '/v/ossp/cvs/ossp-pkg/xds/xds_engine_xdr.c,v' 2>/dev/null --- xds_engine_xdr.c 2001/08/22 20:23:48 1.7 +++ xds_engine_xdr.c 2001/08/23 08:42:50 1.8 @@ -297,17 +297,96 @@ * Encode/decode floating point values. */ +typedef struct + { + unsigned int sign :1; + unsigned int fraction :23; + int exponent :8; + } +myfloat_t; + +static int float2myfloat(myfloat_t* new_num, float num) + { + const static unsigned int base = 2; + size_t i; + float tmp; + + /* Handle zero as a special case. */ + + if (num == 0.0) + { + new_num->sign = 0; + new_num->fraction = 0; + new_num->exponent = -127; + return 0; + } + + /* Determine the sign of the number. */ + + if (num < 0) + { + new_num->sign = 1; + num = 0 - num; + } + else + new_num->sign = 0; + + /* Canonify the number before we convert it. */ + + new_num->exponent = 0; + while (num < 1) + { + num *= base; + --new_num->exponent; + } + + /* Find the exponent. */ + + for (i = 0, tmp = 1; i <= 128; ++i, tmp *= base) + { + if (tmp*base > num) + break; + } + if (i <= 128) + { + num = num / tmp - 1; + new_num->exponent += i; + } + else + return 1; + + /* Calculate the fraction part. */ + + for (new_num->fraction = 0, i = 0; i < 23; ++i) + { + new_num->fraction *= base; + if (num >= 1.0 / base) + { + new_num->fraction |= 1; + num = num * base - 1; + } + else + { + new_num->fraction |= 0; + num *= base; + } + } + + return 0; + } + + int xdr_encode_float(xds_t *xds, void *engine_context, void *buffer, size_t buffer_size, size_t *used_buffer_size, va_list *args) { - xds_float_t value; + myfloat_t value; xds_uint8_t tmp; xds_init_encoding_engine(4); /* Get value and format it into the structure. */ - float2xds_float(&value, (float)va_arg(*args, double)); + float2myfloat(&value, (float)va_arg(*args, double)); memset(buffer, 0, 4);