diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/float.cpp | 38 |
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 | } |
