From b010c4b037f8a8f3760cf20c0f8b907fe11edd99 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 10 Mar 2011 17:50:44 +0000 Subject: 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. --- src/float.cpp | 38 +++++--------------------------------- 1 file changed, 5 insertions(+), 33 deletions(-) (limited to 'src/float.cpp') 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 d = -d; } - if( d == 0.0 ) - { - } - else if( d < 1.0 ) - { - while( d < 1.0 ) - { - d *= 256.0; - iScale--; - } - } - else - { - while( d >= 256.0 ) - { - d *= 0x1p-8; // That's .00390625, or 1/256 - iScale++; - } - } + iScale = log( d ) / 0x1.62e42fefa39efp+2; // log( 256.0 ) + if( iScale < 0 ) iScale--; + d /= pow( 256.0, iScale ); + Bu::String s; s += (uint8_t)(d); d -= (int)d; @@ -128,20 +113,7 @@ void Gats::Float::read( Bu::Stream &rIn, char cType ) fVal += (uint8_t)s[0]; int64_t iScale; Gats::Integer::readPackedInt( rIn, iScale ); - if( iScale < 0 ) - { - for( int64_t j = 0; j > iScale; j-- ) - { - fVal *= 0x1p-8; - } - } - else - { - for( int64_t j = 0; j < iScale; j++ ) - { - fVal *= 256.0; - } - } + fVal *= pow( 256.0, iScale ); if( bNeg ) fVal = -fVal; } } -- cgit v1.2.3