aboutsummaryrefslogtreecommitdiff
path: root/src/unit/float.unit
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-11-09 16:25:22 +0000
committerMike Buland <eichlan@xagasoft.com>2012-11-09 16:25:22 +0000
commit74dd68ad611d15abf16a65c36a7cfd3f4492930a (patch)
tree843fed9ba6bb03253a01314afc3b1dfbb2dfd26c /src/unit/float.unit
parentd9b407475ae3ebe434b29d9eabdd7d4416e17881 (diff)
downloadlibgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.tar.gz
libgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.tar.bz2
libgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.tar.xz
libgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.zip
Made the repo less libbu++-centric.
Diffstat (limited to 'src/unit/float.unit')
-rw-r--r--src/unit/float.unit84
1 files changed, 0 insertions, 84 deletions
diff --git a/src/unit/float.unit b/src/unit/float.unit
deleted file mode 100644
index b1eb063..0000000
--- a/src/unit/float.unit
+++ /dev/null
@@ -1,84 +0,0 @@
1// vim: syntax=cpp
2/*
3 * Copyright (C) 2007-2010 Xagasoft, All rights reserved.
4 *
5 * This file is part of the libbu++ library and is released under the
6 * terms of the license contained in the file LICENSE.
7 */
8
9#include "gats/dictionary.h"
10#include "gats/float.h"
11#include "gats/string.h"
12
13#include "bu/membuf.h"
14#include "bu/list.h"
15#include "bu/sio.h"
16
17#include <stdlib.h>
18#include <math.h>
19
20using namespace Bu;
21
22suite Basic
23{
24 void rw( double dVal )
25 {
26 Bu::MemBuf mb;
27
28 Gats::Float( dVal ).write( mb );
29
30 mb.setPos( 0 );
31
32 Gats::Object *pObj = Gats::Object::read( mb );
33 unitTest( pObj != NULL );
34 unitTest( pObj->getType() == Gats::typeFloat );
35 Gats::Float *pFlt = dynamic_cast<Gats::Float *>(pObj);
36 Bu::String sHex;
37 for( Bu::String::iterator i = mb.getString().begin(); i; i++ )
38 {
39 sHex += "0123456789abcdef"[(((uint8_t)*i)>>4)&0x0f];
40 sHex += "0123456789abcdef"[(*i)&0x0f];
41 sHex += ' ';
42 }
43 printf("In: %a\nOut: %a\nRaw: %s\n", dVal, pFlt->getValue(), sHex.getStr() );
44 if( isnan( dVal ) )
45 unitTest( isnan(pFlt->getValue()) == isnan(dVal) );
46 else
47 unitTest( pFlt->getValue() == dVal );
48 unitTest( signbit(pFlt->getValue()) == signbit(dVal) );
49
50 delete pObj;
51 }
52
53 test positive
54 {
55 rw( 8485738457.0 );
56 rw( 63723.0 );
57 rw( 0.000000000000001928173 );
58 rw( 1.0 );
59 rw( 0.0 );
60 rw( M_PI );
61 }
62
63 test negitave
64 {
65 rw( -8485738457.0 );
66 rw( -63723.0 );
67 rw( -0.000000000000001928173 );
68 rw( -1.0 );
69 rw( -0.0 );
70 rw( -M_PI );
71 }
72
73 test inf
74 {
75 rw( INFINITY );
76 rw( -INFINITY );
77 }
78
79 test nan
80 {
81 rw( NAN );
82 rw( -NAN );
83 }
84}