aboutsummaryrefslogtreecommitdiff
path: root/src/float.cpp
blob: 879d74b18ccca3fdf1ac5e04681982353bf3a11d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "gats/float.h"
#include "gats/integer.h"

#include <bu/formatter.h>

Gats::Float::Float() :
	fVal( 0.0 )
{
}

Gats::Float::Float( double f ) :
	fVal( f )
{
}

Gats::Float::~Float()
{
}

void Gats::Float::write( Bu::Stream &rOut ) const
{
	if( sWriteCache.isEmpty() )
	{
		char buf[50];

		int iSize = snprintf( buf, 50, "%la", fVal );
		sWriteCache.set( buf, iSize );
	}
	rOut.write("f", 1 );
	Gats::Integer::writePackedInt( rOut, sWriteCache.getSize() );
	rOut.write( sWriteCache.getStr(), sWriteCache.getSize() );
}

void Gats::Float::read( Bu::Stream &rIn, char cType )
{
	int iSize;
	Gats::Integer::readPackedInt( rIn, iSize );
	char buf[50];
	buf[rIn.read( buf, iSize )] = '\0';
	sscanf( buf, "%la", &fVal );
}

Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Float &flt )
{
	return f << "(float) " << flt.getValue();
}