Check-in Number:
|
751 | |
Date: |
2001-Aug-23 10:42:49 (local)
2001-Aug-23 08:42:49 (UTC) |
User: | simons |
Branch: | |
Comment: |
- Moved all float-related stuff into xds_engine_xdr.c so that we don't
need any prototypes or structure declarations in the public header
file.
- Renamed xds_float_t to my_float.
- Renamed float2xds_float() to float2myfloat(). |
Tickets: |
|
Inspections: |
|
Files: |
|
ossp-pkg/xds/Makefile.in 1.33 -> 1.34
--- 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
|
|
ossp-pkg/xds/float2xds-float.c -> 1.2
*** /dev/null Tue Mar 11 06:01:42 2025
--- - Tue Mar 11 06:02:25 2025
***************
*** 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;
+ }
|
|
ossp-pkg/xds/xds.h.in 1.15 -> 1.16
--- 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__ */
|
|
ossp-pkg/xds/xds_engine_xdr.c 1.7 -> 1.8
--- 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);
|
|