aboutsummaryrefslogtreecommitdiff
path: root/src/float.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-03-10 17:50:44 +0000
committerMike Buland <eichlan@xagasoft.com>2011-03-10 17:50:44 +0000
commitb010c4b037f8a8f3760cf20c0f8b907fe11edd99 (patch)
treeb7f60b65ac236aad07e6d303486a54a972fdf7ea /src/float.cpp
parent744fe4ecbcf613ee637d00e8808f69668eac6bb2 (diff)
downloadlibgats-b010c4b037f8a8f3760cf20c0f8b907fe11edd99.tar.gz
libgats-b010c4b037f8a8f3760cf20c0f8b907fe11edd99.tar.bz2
libgats-b010c4b037f8a8f3760cf20c0f8b907fe11edd99.tar.xz
libgats-b010c4b037f8a8f3760cf20c0f8b907fe11edd99.zip
Float format is pretty much stabalized. I switched to using log/exp to scale
the number, works very well. The output is still encoded with bytes as base-256 digits of the number.
Diffstat (limited to 'src/float.cpp')
-rw-r--r--src/float.cpp38
1 files changed, 5 insertions, 33 deletions
diff --git a/src/float.cpp b/src/float.cpp
index f1e9ced..1b4ebae 100644
--- a/src/float.cpp
+++ b/src/float.cpp
@@ -58,25 +58,10 @@ void Gats::Float::write( Bu::Stream &rOut ) const
58 d = -d; 58 d = -d;
59 } 59 }
60 60
61 if( d == 0.0 ) 61 iScale = log( d ) / 0x1.62e42fefa39efp+2; // log( 256.0 )
62 { 62 if( iScale < 0 ) iScale--;
63 } 63 d /= pow( 256.0, iScale );
64 else if( d < 1.0 ) 64
65 {
66 while( d < 1.0 )
67 {
68 d *= 256.0;
69 iScale--;
70 }
71 }
72 else
73 {
74 while( d >= 256.0 )
75 {
76 d *= 0x1p-8; // That's .00390625, or 1/256
77 iScale++;
78 }
79 }
80 Bu::String s; 65 Bu::String s;
81 s += (uint8_t)(d); 66 s += (uint8_t)(d);
82 d -= (int)d; 67 d -= (int)d;
@@ -128,20 +113,7 @@ void Gats::Float::read( Bu::Stream &rIn, char cType )
128 fVal += (uint8_t)s[0]; 113 fVal += (uint8_t)s[0];
129 int64_t iScale; 114 int64_t iScale;
130 Gats::Integer::readPackedInt( rIn, iScale ); 115 Gats::Integer::readPackedInt( rIn, iScale );
131 if( iScale < 0 ) 116 fVal *= pow( 256.0, iScale );
132 {
133 for( int64_t j = 0; j > iScale; j-- )
134 {
135 fVal *= 0x1p-8;
136 }
137 }
138 else
139 {
140 for( int64_t j = 0; j < iScale; j++ )
141 {
142 fVal *= 256.0;
143 }
144 }
145 if( bNeg ) fVal = -fVal; 117 if( bNeg ) fVal = -fVal;
146 } 118 }
147} 119}