OSSP CVS Repository

ossp - Check-in [4311]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 4311
Date: 2001-Aug-22 22:21:01 (local)
2001-Aug-22 20:21:01 (UTC)
User:simons
Branch:
Comment: The float2xds_float() routine will break a float number down into sign, fraction part and exponent. This representation is then used in the formatting callbacks such as xdr_encode_float().
Tickets:
Inspections:
Files:
ossp-pkg/xds/float2xds-float.c      added-> 1.1

ossp-pkg/xds/float2xds-float.c -> 1.1

*** /dev/null    Mon Apr 29 08:04:01 2024
--- -    Mon Apr 29 08:04:15 2024
***************
*** 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;
+     }

CVSTrac 2.0.1