-
Notifications
You must be signed in to change notification settings - Fork 3
/
FracType.cpp
51 lines (47 loc) · 865 Bytes
/
FracType.cpp
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
48
49
50
51
#include "FracType.h"
double logAdd(double logx, double logy)
{
if(abs(logx)>308)return logy;
if(abs(logy)>308)return logx;
return logx+log1p(exp(logy-logx));
}
double discountMass(FracType& ft, vector<double>& discount)
{
double mass=0;
double n3=1-ft[0]-ft[1]-ft[2];
if(n3<0)n3=ft[3];
mass=(LogDouble)discount[0]*ft[1]+(LogDouble)discount[1]*ft[2]+
(LogDouble)discount[2]*(LogDouble)n3;
return mass;
}
int
FracType::
compare(FracType& f)
{
for(int i=0;i<5;i++)
{
if(abs((*this)[i]-f[i])>1E-10)
{
cerr<<(*this)[i]<<"!="<<f[i]<<endl;
return i;
}
}
return -1;
}
void
FracType::
update(double p)
{
FracType& t=*this;
while(p>1.01)
{
update(1);
p-=1;
}
if(p==0)return;
for(int i=4;i>0;i--)
t[i]=t[i-1]*(LogDouble)p+t[i]*(LogDouble)(1-p);
t[0]*=(LogDouble)(1-p);
//print(cerr);
//cerr<<endl;
}