aboutsummaryrefslogtreecommitdiff
path: root/src/float.cpp
blob: 139df3e2224de6598f17e03fc6e86df5641f8328 (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
#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
{
	char buf[50];

	int iSize = snprintf( buf, 50, "%la", fVal );

	rOut.write("f", 1 );
	Gats::Integer::writePackedInt( rOut, iSize );
	rOut.write( buf, iSize );
}

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

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