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.14 by greg, Sat Dec 23 17:27:45 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines