Skip to content

Commit 0054f73

Browse files
massjhunsaker
authored andcommitted
Convert fact_ and decay_ to signed integers.
1 parent 6120be9 commit 0054f73

File tree

4 files changed

+66
-58
lines changed

4 files changed

+66
-58
lines changed

pctest/test_qset.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ int usage()
2323

2424
void test_pd()
2525
{
26-
const uint64_t dec_fact[] = {
27-
1UL, 10UL, 100UL, 1000UL, 10000UL, 100000UL, 1000000UL, 10000000UL,
28-
100000000UL, 1000000000UL, 10000000000UL, 100000000000UL, 1000000000000UL,
29-
10000000000000UL, 100000000000000UL, 1000000000000000UL, 10000000000000000UL,
30-
100000000000000000UL
26+
const int64_t dec_fact[] = {
27+
1L, 10L, 100L, 1000L, 10000L, 100000L, 1000000L, 10000000L,
28+
100000000L, 1000000000L, 10000000000L, 100000000000L, 1000000000000L,
29+
10000000000000L, 100000000000000L, 1000000000000000L, 10000000000000000L,
30+
100000000000000000L
3131
};
3232
// construct calculator
3333
pd_t m[1], s[1];
@@ -84,6 +84,14 @@ void test_pd()
8484
pd_sub( r, n2, n1, dec_fact );
8585
PC_TEST_CHECK( r->v_ == -123 && r->e_ == 27 );
8686

87+
// test add negative numbers
88+
pd_new( n1, -140205667, -13 );
89+
pd_new( n2, 42901738, -3 );
90+
pd_add( r, n1, n2, dec_fact );
91+
PC_TEST_CHECK( r->v_ == 42901737 && r->e_ == -3 );
92+
pd_add( r, n2, n1, dec_fact );
93+
PC_TEST_CHECK( r->v_ == 42901737 && r->e_ == -3 );
94+
8795
pd_new( n1, 1010, -9 );
8896
pd_new( n2, 102, -8 );
8997
PC_TEST_CHECK( pd_lt( n1, n2, dec_fact ) );

program/src/oracle/oracle.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ typedef struct pc_qset
167167
pd_t lprice_[PC_COMP_SIZE];
168168
pd_t weight_[PC_COMP_SIZE];
169169
pd_t cumwgt_[PC_COMP_SIZE];
170-
uint64_t decay_[1+PC_MAX_SEND_LATENCY];
171-
uint64_t fact_[PC_FACTOR_SIZE];
170+
int64_t decay_[1+PC_MAX_SEND_LATENCY];
171+
int64_t fact_[PC_FACTOR_SIZE];
172172
uint32_t num_;
173173
int32_t expo_;
174174
} pc_qset_t;

program/src/oracle/upd_aggregate.h

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static void pd_scale( pd_t *n )
2121
n->v_ = neg ? -v : v;
2222
}
2323

24-
static void pd_adjust( pd_t *n, int e, const uint64_t *p )
24+
static void pd_adjust( pd_t *n, int e, const int64_t *p )
2525
{
2626
int neg = n->v_ < 0L;
2727
uint64_t v = neg?-n->v_:n->v_;
@@ -52,7 +52,7 @@ static void pd_div( pd_t *r, pd_t *n1, pd_t *n2 )
5252
pd_scale( r );
5353
}
5454

55-
static void pd_add( pd_t *r, pd_t *n1, pd_t *n2, const uint64_t *p )
55+
static void pd_add( pd_t *r, pd_t *n1, pd_t *n2, const int64_t *p )
5656
{
5757
int d = n1->e_ - n2->e_;
5858
if ( d==0 ) {
@@ -78,7 +78,7 @@ static void pd_add( pd_t *r, pd_t *n1, pd_t *n2, const uint64_t *p )
7878
pd_scale( r );
7979
}
8080

81-
static void pd_sub( pd_t *r, pd_t *n1, pd_t *n2, const uint64_t *p )
81+
static void pd_sub( pd_t *r, pd_t *n1, pd_t *n2, const int64_t *p )
8282
{
8383
int d = n1->e_ - n2->e_;
8484
if ( d==0 ) {
@@ -104,21 +104,21 @@ static void pd_sub( pd_t *r, pd_t *n1, pd_t *n2, const uint64_t *p )
104104
pd_scale( r );
105105
}
106106

107-
static int pd_lt( pd_t *n1, pd_t *n2, const uint64_t *p )
107+
static int pd_lt( pd_t *n1, pd_t *n2, const int64_t *p )
108108
{
109109
pd_t r[1];
110110
pd_sub( r, n1, n2, p );
111111
return r->v_ < 0L;
112112
}
113113

114-
static int pd_gt( pd_t *n1, pd_t *n2, const uint64_t *p )
114+
static int pd_gt( pd_t *n1, pd_t *n2, const int64_t *p )
115115
{
116116
pd_t r[1];
117117
pd_sub( r, n1, n2, p );
118118
return r->v_ > 0L;
119119
}
120120

121-
static void pd_sqrt( pd_t *r, pd_t *val, const uint64_t *f )
121+
static void pd_sqrt( pd_t *r, pd_t *val, const int64_t *f )
122122
{
123123
pd_t t[1], x[1], hlf[1];
124124
pd_set( t, val );
@@ -144,52 +144,52 @@ static pc_qset_t *qset_new( int expo )
144144
pc_qset_t *qs = (pc_qset_t*)PC_HEAP_START;
145145

146146
// sqrt of numbers 1 to 25 for decaying conf. interval based on slot delay
147-
qs->decay_[0] = 1000000000UL;
148-
qs->decay_[1] = 1000000000UL;
149-
qs->decay_[2] = 1414213562UL;
150-
qs->decay_[3] = 1732050807UL;
151-
qs->decay_[4] = 2000000000UL;
152-
qs->decay_[5] = 2236067977UL;
153-
qs->decay_[6] = 2449489742UL;
154-
qs->decay_[7] = 2645751311UL;
155-
qs->decay_[8] = 2828427124UL;
156-
qs->decay_[9] = 3000000000UL;
157-
qs->decay_[10] = 3162277660UL;
158-
qs->decay_[11] = 3316624790UL;
159-
qs->decay_[12] = 3464101615UL;
160-
qs->decay_[13] = 3605551275UL;
161-
qs->decay_[14] = 3741657386UL;
162-
qs->decay_[15] = 3872983346UL;
163-
qs->decay_[16] = 4000000000UL;
164-
qs->decay_[17] = 4123105625UL;
165-
qs->decay_[18] = 4242640687UL;
166-
qs->decay_[19] = 4358898943UL;
167-
qs->decay_[20] = 4472135954UL;
168-
qs->decay_[21] = 4582575694UL;
169-
qs->decay_[22] = 4690415759UL;
170-
qs->decay_[23] = 4795831523UL;
171-
qs->decay_[24] = 4898979485UL;
172-
qs->decay_[25] = 5000000000UL;
147+
qs->decay_[0] = 1000000000L;
148+
qs->decay_[1] = 1000000000L;
149+
qs->decay_[2] = 1414213562L;
150+
qs->decay_[3] = 1732050807L;
151+
qs->decay_[4] = 2000000000L;
152+
qs->decay_[5] = 2236067977L;
153+
qs->decay_[6] = 2449489742L;
154+
qs->decay_[7] = 2645751311L;
155+
qs->decay_[8] = 2828427124L;
156+
qs->decay_[9] = 3000000000L;
157+
qs->decay_[10] = 3162277660L;
158+
qs->decay_[11] = 3316624790L;
159+
qs->decay_[12] = 3464101615L;
160+
qs->decay_[13] = 3605551275L;
161+
qs->decay_[14] = 3741657386L;
162+
qs->decay_[15] = 3872983346L;
163+
qs->decay_[16] = 4000000000L;
164+
qs->decay_[17] = 4123105625L;
165+
qs->decay_[18] = 4242640687L;
166+
qs->decay_[19] = 4358898943L;
167+
qs->decay_[20] = 4472135954L;
168+
qs->decay_[21] = 4582575694L;
169+
qs->decay_[22] = 4690415759L;
170+
qs->decay_[23] = 4795831523L;
171+
qs->decay_[24] = 4898979485L;
172+
qs->decay_[25] = 5000000000L;
173173

174174
// powers of 10 for use in decimal arithmetic scaling
175-
qs->fact_[0] = 1UL;
176-
qs->fact_[1] = 10UL;
177-
qs->fact_[2] = 100UL;
178-
qs->fact_[3] = 1000UL;
179-
qs->fact_[4] = 10000UL;
180-
qs->fact_[5] = 100000UL;
181-
qs->fact_[6] = 1000000UL;
182-
qs->fact_[7] = 10000000UL;
183-
qs->fact_[8] = 100000000UL;
184-
qs->fact_[9] = 1000000000UL;
185-
qs->fact_[10] = 10000000000UL;
186-
qs->fact_[11] = 100000000000UL;
187-
qs->fact_[12] = 1000000000000UL;
188-
qs->fact_[13] = 10000000000000UL;
189-
qs->fact_[14] = 100000000000000UL;
190-
qs->fact_[15] = 1000000000000000UL;
191-
qs->fact_[16] = 10000000000000000UL;
192-
qs->fact_[17] = 100000000000000000UL;
175+
qs->fact_[0] = 1L;
176+
qs->fact_[1] = 10L;
177+
qs->fact_[2] = 100L;
178+
qs->fact_[3] = 1000L;
179+
qs->fact_[4] = 10000L;
180+
qs->fact_[5] = 100000L;
181+
qs->fact_[6] = 1000000L;
182+
qs->fact_[7] = 10000000L;
183+
qs->fact_[8] = 100000000L;
184+
qs->fact_[9] = 1000000000L;
185+
qs->fact_[10] = 10000000000L;
186+
qs->fact_[11] = 100000000000L;
187+
qs->fact_[12] = 1000000000000L;
188+
qs->fact_[13] = 10000000000000L;
189+
qs->fact_[14] = 100000000000000L;
190+
qs->fact_[15] = 1000000000000000L;
191+
qs->fact_[16] = 10000000000000000L;
192+
qs->fact_[17] = 100000000000000000L;
193193

194194
qs->num_ = 0;
195195
qs->expo_ = expo;

pyth/tests/qset/34.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"exponent":-8,"price":4290171000000,"conf":92233722000000}
1+
{"exponent":-8,"price":4290171000000,"conf":59750000}

0 commit comments

Comments
 (0)