ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/portio.c
(Generate patch)

Comparing ray/src/common/portio.c (file contents):
Revision 2.7 by greg, Tue Feb 25 02:47:21 2003 UTC vs.
Revision 2.13 by greg, Tue May 3 05:10:13 2005 UTC

# Line 11 | Line 11 | static const char      RCSid[] = "$Id$";
11  
12   #include <stdio.h>
13  
14 < #ifndef frexp
15 < extern double  frexp();
14 > #include "rtio.h"
15 >
16 > #include <math.h>
17 >
18 > #ifdef getc_unlocked            /* avoid horrendous overhead of flockfile */
19 > #undef getc
20 > #undef putc
21 > #define getc    getc_unlocked
22 > #define putc    putc_unlocked
23   #endif
17 #ifndef ldexp
18 extern double  ldexp();
19 #endif
24  
25  
26   void
# Line 46 | Line 50 | putflt(f, fp)                  /* put out floating point number */
50   double  f;
51   FILE  *fp;
52   {
53 +        long  m;
54          int  e;
55  
56 <        putint((long)(frexp(f,&e)*0x7fffffff), 4, fp);
56 >        m = frexp(f, &e) * 0x7fffffff;
57 >        if (e > 127) {                  /* overflow */
58 >                m = m > 0 ? (long)0x7fffffff : -(long)0x7fffffff;
59 >                e = 127;
60 >        } else if (e < -128) {          /* underflow */
61 >                m = 0;
62 >                e = 0;
63 >        }
64 >        putint(m, 4, fp);
65          putint((long)e, 1, fp);
66   }
67  
# Line 99 | Line 112 | FILE  *fp;
112          double  d;
113  
114          l = getint(4, fp);
115 +        if (l == 0) {
116 +                getc(fp);               /* exactly zero -- ignore exponent */
117 +                return(0.0);
118 +        }
119          d = (l + (l > 0 ? .5 : -.5)) * (1./0x7fffffff);
120          return(ldexp(d, (int)getint(1, fp)));
121   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines