// vim: sw=4 ts=2 sta et #include #include #include #include /* life insurance calculation */ #define MAXAGE 100 static double mortality_male[MAXAGE + 1] = { 0.00744, 0.00046, 0.00031, 0.00022, 0.00019, 0.00020, 0.00020, 0.00018, 0.00017, 0.00017 , 0.00017, 0.00018, 0.00019, 0.00023, 0.00029, 0.00036, 0.00046, 0.00059, 0.00075, 0.00090 , 0.00103, 0.00111, 0.00114, 0.00113, 0.00112, 0.00115, 0.00120, 0.00126, 0.00132, 0.00139 , 0.00147, 0.00158, 0.00171, 0.00187, 0.00205, 0.00224, 0.00244, 0.00264, 0.00287, 0.00313 , 0.00344, 0.00381, 0.00427, 0.00478, 0.00535, 0.00596, 0.00659, 0.00725, 0.00793, 0.00867 , 0.00946, 0.01030, 0.01119, 0.01211, 0.01306, 0.01402, 0.01503, 0.01613, 0.01733, 0.01865 , 0.02008, 0.02162, 0.02326, 0.02500, 0.02687, 0.02889, 0.03105, 0.03340, 0.03592, 0.03864 , 0.04159, 0.04479, 0.04824, 0.05197, 0.05597, 0.06034, 0.06513, 0.07049, 0.07668, 0.08373 , 0.09149, 0.09993, 0.10823, 0.11645, 0.12476, 0.13228, 0.14256, 0.15356, 0.16530, 0.17781 , 0.19112, 0.20526, 0.22024, 0.23608, 0.25279, 0.27037, 0.28883, 0.30816, 0.32834, 0.34935 , 0.37116 }; static double mortality_female[MAXAGE + 1] = { 0.00615, 0.00033, 0.00024, 0.00018, 0.00016, 0.00014, 0.00012, 0.00011, 0.00011, 0.00012 , 0.00012, 0.00012, 0.00013, 0.00015, 0.00018, 0.00023, 0.00027, 0.00028, 0.00027, 0.00028 , 0.00029, 0.00029, 0.00027, 0.00026, 0.00026, 0.00028, 0.00030, 0.00032, 0.00035, 0.00037 , 0.00040, 0.00043, 0.00046, 0.00050, 0.00055, 0.00060, 0.00067, 0.00075, 0.00085, 0.00097 , 0.00112, 0.00129, 0.00148, 0.00169, 0.00191, 0.00214, 0.00237, 0.00263, 0.00290, 0.00319 , 0.00351, 0.00384, 0.00418, 0.00453, 0.00489, 0.00527, 0.00568, 0.00611, 0.00657, 0.00706 , 0.00758, 0.00815, 0.00880, 0.00953, 0.01036, 0.01131, 0.01238, 0.01360, 0.01501, 0.01666 , 0.01856, 0.02076, 0.02323, 0.02603, 0.02921, 0.03282, 0.03695, 0.04171, 0.04724, 0.05357 , 0.06060, 0.06840, 0.07650, 0.08499, 0.09402, 0.10310, 0.11440, 0.12669, 0.14002, 0.15444 , 0.16997, 0.18666, 0.20452, 0.22357, 0.24383, 0.26527, 0.28789, 0.31166, 0.33653, 0.36245 , 0.38934 }; #define GENDER_MALE 0 #define GENDER_FEMALE 1 static double *mortality[] ={ mortality_male, mortality_female }; static double mortality_max[2] = { 0.37116, 0.38934 }; static double vn_precomputed[MAXAGE]; typedef struct { double abw; double ebw; double rbw; } struct_barwert_result; typedef struct { double irate; /* indizes: gender (0/1), age (0..130), duration (0..50) */ struct_barwert_result results[2][131][51]; } struct_barwert_addrisk0_cache; static struct_barwert_addrisk0_cache barwert_caches[2]; static int isBarwertPrecomputed=0; static void precompute_vn_irate(double irate, int n) { int i; for (i=0; i<=n; i++) { vn_precomputed[i] = 1 / pow(1 + irate, (double) i); } } static double vn(int n) { return vn_precomputed[n]; } static double qx(int x, int gender, double addrisk) { double q = x>100 ? 1 : (mortality[gender][x] + addrisk); return q > 1 ? 1 : q; } static double qx_addrisk0(int x, int gender) { return mortality[gender][x]; } static void barwert_common(int x, int gender, double irate, double addrisk, int n, double *abw, double *ebw, double *rbw) { int i; double p=1; double q; *abw = 0; *rbw = 0; int over100 = (MAXAGE + 1) - x; int top = over100 < n ? over100 : n; /* nAx, aexn */ for (i=0; i < top; i++) { q = qx(x+i, gender, addrisk); *abw += p * q * vn(i+1); *rbw += p * vn(i); p *= (1-q); } // skip loop until `n', because in the next steps `p' would be zero anyways if (i < n) { *abw += p * vn(i+1); *rbw += p * vn(i); p = 0; } /* nEx */ *ebw = p * vn(n); } static void bw_m(int x, int n, double addrisk, double *abw, double *ebw, double *rbw) { double p=1, q; int i=0; double ret_abw=0, ret_rbw=0; static void *l[] = { &&i0, &&i1, &&i2, &&i3, &&i4, &&i5, &&i6, &&i7, &&i8, &&i9, &&i10, &&i11, &&i12, &&i13, &&i14, &&i15, &&i16, &&i17, &&i18, &&i19, &&i20, &&i21, &&i22, &&i23, &&i24, &&i25, &&i26, &&i27, &&i28, &&i29, &&i30, &&i31, &&i32, &&i33, &&i34, &&i35, &&i36, &&i37, &&i38, &&i39, &&i40, &&i41, &&i42, &&i43, &&i44, &&i45, &&i46, &&i47, &&i48, &&i49, &&i50, &&i51, &&i52, &&i53, &&i54, &&i55, &&i56, &&i57, &&i58, &&i59, &&i60, &&i61, &&i62, &&i63, &&i64, &&i65, &&i66, &&i67, &&i68, &&i69, &&i70, &&i71, &&i72, &&i73, &&i74, &&i75, &&i76, &&i77, &&i78, &&i79, &&i80, &&i81, &&i82, &&i83, &&i84, &&i85, &&i86, &&i87, &&i88, &&i89, &&i90, &&i91, &&i92, &&i93, &&i94, &&i95, &&i96, &&i97, &&i98, &&i99, &&i100, &&i101}; goto *l[x]; i0: /* x=0 */ q = 0.00744 + addrisk; ret_rbw = 1; ret_abw = q * vn_precomputed[1]; p = (1-q); i = 1; if (i>=n) goto end; i1: /* x=1 */ q = 0.00046 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i2: /* x=2 */ q = 0.00031 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i3: /* x=3 */ q = 0.00022 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i4: /* x=4 */ q = 0.00019 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i5: /* x=5 */ q = 0.0002 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i6: /* x=6 */ q = 0.0002 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i7: /* x=7 */ q = 0.00018 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i8: /* x=8 */ q = 0.00017 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i9: /* x=9 */ q = 0.00017 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i10: /* x=10 */ q = 0.00017 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i11: /* x=11 */ q = 0.00018 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i12: /* x=12 */ q = 0.00019 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i13: /* x=13 */ q = 0.00023 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i14: /* x=14 */ q = 0.00029 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i15: /* x=15 */ q = 0.00036 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i16: /* x=16 */ q = 0.00046 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i17: /* x=17 */ q = 0.00059 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i18: /* x=18 */ q = 0.00075 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i19: /* x=19 */ q = 0.0009 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i20: /* x=20 */ q = 0.00103 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i21: /* x=21 */ q = 0.00111 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i22: /* x=22 */ q = 0.00114 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i23: /* x=23 */ q = 0.00113 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i24: /* x=24 */ q = 0.00112 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i25: /* x=25 */ q = 0.00115 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i26: /* x=26 */ q = 0.0012 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i27: /* x=27 */ q = 0.00126 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i28: /* x=28 */ q = 0.00132 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i29: /* x=29 */ q = 0.00139 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i30: /* x=30 */ q = 0.00147 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i31: /* x=31 */ q = 0.00158 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i32: /* x=32 */ q = 0.00171 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i33: /* x=33 */ q = 0.00187 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i34: /* x=34 */ q = 0.00205 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i35: /* x=35 */ q = 0.00224 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i36: /* x=36 */ q = 0.00244 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i37: /* x=37 */ q = 0.00264 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i38: /* x=38 */ q = 0.00287 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i39: /* x=39 */ q = 0.00313 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i40: /* x=40 */ q = 0.00344 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i41: /* x=41 */ q = 0.00381 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i42: /* x=42 */ q = 0.00427 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i43: /* x=43 */ q = 0.00478 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i44: /* x=44 */ q = 0.00535 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i45: /* x=45 */ q = 0.00596 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i46: /* x=46 */ q = 0.00659 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i47: /* x=47 */ q = 0.00725 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i48: /* x=48 */ q = 0.00793 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i49: /* x=49 */ q = 0.00867 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i50: /* x=50 */ q = 0.00946 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i51: /* x=51 */ q = 0.0103 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i52: /* x=52 */ q = 0.01119 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i53: /* x=53 */ q = 0.01211 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i54: /* x=54 */ q = 0.01306 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i55: /* x=55 */ q = 0.01402 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i56: /* x=56 */ q = 0.01503 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i57: /* x=57 */ q = 0.01613 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i58: /* x=58 */ q = 0.01733 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i59: /* x=59 */ q = 0.01865 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i60: /* x=60 */ q = 0.02008 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i61: /* x=61 */ q = 0.02162 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i62: /* x=62 */ q = 0.02326 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i63: /* x=63 */ q = 0.025 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i64: /* x=64 */ q = 0.02687 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i65: /* x=65 */ q = 0.02889 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i66: /* x=66 */ q = 0.03105 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i67: /* x=67 */ q = 0.0334 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i68: /* x=68 */ q = 0.03592 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i69: /* x=69 */ q = 0.03864 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i70: /* x=70 */ q = 0.04159 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i71: /* x=71 */ q = 0.04479 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i72: /* x=72 */ q = 0.04824 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i73: /* x=73 */ q = 0.05197 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i74: /* x=74 */ q = 0.05597 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i75: /* x=75 */ q = 0.06034 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i76: /* x=76 */ q = 0.06513 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i77: /* x=77 */ q = 0.07049 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i78: /* x=78 */ q = 0.07668 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i79: /* x=79 */ q = 0.08373 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i80: /* x=80 */ q = 0.09149 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i81: /* x=81 */ q = 0.09993 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i82: /* x=82 */ q = 0.10823 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i83: /* x=83 */ q = 0.11645 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i84: /* x=84 */ q = 0.12476 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i85: /* x=85 */ q = 0.13228 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i86: /* x=86 */ q = 0.14256 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i87: /* x=87 */ q = 0.15356 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i88: /* x=88 */ q = 0.1653 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i89: /* x=89 */ q = 0.17781 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i90: /* x=90 */ q = 0.19112 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i91: /* x=91 */ q = 0.20526 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i92: /* x=92 */ q = 0.22024 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i93: /* x=93 */ q = 0.23608 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i94: /* x=94 */ q = 0.25279 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i95: /* x=95 */ q = 0.27037 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i96: /* x=96 */ q = 0.28883 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i97: /* x=97 */ q = 0.30816 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i98: /* x=98 */ q = 0.32834 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i99: /* x=99 */ q = 0.34935 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i100: /* x=100 */ q = 0.37116 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i101: /* x=101 */ *rbw = ret_rbw + p * vn_precomputed[i]; *abw = ret_abw + p * vn_precomputed[i+1]; *ebw = 0; return; end: *ebw = p * vn_precomputed[n]; *abw = ret_abw; *rbw = ret_rbw; } static void bw_f(int x, int n, double addrisk, double *abw, double *ebw, double *rbw) { double p=1, q; int i=0; double ret_abw=0, ret_rbw=0; static void *l[] = { &&i0, &&i1, &&i2, &&i3, &&i4, &&i5, &&i6, &&i7, &&i8, &&i9, &&i10, &&i11, &&i12, &&i13, &&i14, &&i15, &&i16, &&i17, &&i18, &&i19, &&i20, &&i21, &&i22, &&i23, &&i24, &&i25, &&i26, &&i27, &&i28, &&i29, &&i30, &&i31, &&i32, &&i33, &&i34, &&i35, &&i36, &&i37, &&i38, &&i39, &&i40, &&i41, &&i42, &&i43, &&i44, &&i45, &&i46, &&i47, &&i48, &&i49, &&i50, &&i51, &&i52, &&i53, &&i54, &&i55, &&i56, &&i57, &&i58, &&i59, &&i60, &&i61, &&i62, &&i63, &&i64, &&i65, &&i66, &&i67, &&i68, &&i69, &&i70, &&i71, &&i72, &&i73, &&i74, &&i75, &&i76, &&i77, &&i78, &&i79, &&i80, &&i81, &&i82, &&i83, &&i84, &&i85, &&i86, &&i87, &&i88, &&i89, &&i90, &&i91, &&i92, &&i93, &&i94, &&i95, &&i96, &&i97, &&i98, &&i99, &&i100, &&i101}; goto *l[x]; i0: /* x=0 */ q = 0.00615 + addrisk; ret_rbw = 1; ret_abw = q * vn_precomputed[1]; p = (1-q); i = 1; if (i>=n) goto end; i1: /* x=1 */ q = 0.00033 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i2: /* x=2 */ q = 0.00024 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i3: /* x=3 */ q = 0.00018 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i4: /* x=4 */ q = 0.00016 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i5: /* x=5 */ q = 0.00014 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i6: /* x=6 */ q = 0.00012 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i7: /* x=7 */ q = 0.00011 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i8: /* x=8 */ q = 0.00011 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i9: /* x=9 */ q = 0.00012 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i10: /* x=10 */ q = 0.00012 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i11: /* x=11 */ q = 0.00012 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i12: /* x=12 */ q = 0.00013 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i13: /* x=13 */ q = 0.00015 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i14: /* x=14 */ q = 0.00018 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i15: /* x=15 */ q = 0.00023 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i16: /* x=16 */ q = 0.00027 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i17: /* x=17 */ q = 0.00028 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i18: /* x=18 */ q = 0.00027 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i19: /* x=19 */ q = 0.00028 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i20: /* x=20 */ q = 0.00029 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i21: /* x=21 */ q = 0.00029 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i22: /* x=22 */ q = 0.00027 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i23: /* x=23 */ q = 0.00026 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i24: /* x=24 */ q = 0.00026 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i25: /* x=25 */ q = 0.00028 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i26: /* x=26 */ q = 0.0003 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i27: /* x=27 */ q = 0.00032 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i28: /* x=28 */ q = 0.00035 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i29: /* x=29 */ q = 0.00037 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i30: /* x=30 */ q = 0.0004 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i31: /* x=31 */ q = 0.00043 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i32: /* x=32 */ q = 0.00046 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i33: /* x=33 */ q = 0.0005 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i34: /* x=34 */ q = 0.00055 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i35: /* x=35 */ q = 0.0006 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i36: /* x=36 */ q = 0.00067 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i37: /* x=37 */ q = 0.00075 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i38: /* x=38 */ q = 0.00085 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i39: /* x=39 */ q = 0.00097 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i40: /* x=40 */ q = 0.00112 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i41: /* x=41 */ q = 0.00129 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i42: /* x=42 */ q = 0.00148 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i43: /* x=43 */ q = 0.00169 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i44: /* x=44 */ q = 0.00191 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i45: /* x=45 */ q = 0.00214 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i46: /* x=46 */ q = 0.00237 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i47: /* x=47 */ q = 0.00263 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i48: /* x=48 */ q = 0.0029 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i49: /* x=49 */ q = 0.00319 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i50: /* x=50 */ q = 0.00351 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i51: /* x=51 */ q = 0.00384 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i52: /* x=52 */ q = 0.00418 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i53: /* x=53 */ q = 0.00453 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i54: /* x=54 */ q = 0.00489 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i55: /* x=55 */ q = 0.00527 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i56: /* x=56 */ q = 0.00568 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i57: /* x=57 */ q = 0.00611 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i58: /* x=58 */ q = 0.00657 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i59: /* x=59 */ q = 0.00706 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i60: /* x=60 */ q = 0.00758 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i61: /* x=61 */ q = 0.00815 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i62: /* x=62 */ q = 0.0088 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i63: /* x=63 */ q = 0.00953 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i64: /* x=64 */ q = 0.01036 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i65: /* x=65 */ q = 0.01131 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i66: /* x=66 */ q = 0.01238 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i67: /* x=67 */ q = 0.0136 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i68: /* x=68 */ q = 0.01501 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i69: /* x=69 */ q = 0.01666 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i70: /* x=70 */ q = 0.01856 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i71: /* x=71 */ q = 0.02076 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i72: /* x=72 */ q = 0.02323 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i73: /* x=73 */ q = 0.02603 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i74: /* x=74 */ q = 0.02921 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i75: /* x=75 */ q = 0.03282 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i76: /* x=76 */ q = 0.03695 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i77: /* x=77 */ q = 0.04171 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i78: /* x=78 */ q = 0.04724 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i79: /* x=79 */ q = 0.05357 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i80: /* x=80 */ q = 0.0606 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i81: /* x=81 */ q = 0.0684 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i82: /* x=82 */ q = 0.0765 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i83: /* x=83 */ q = 0.08499 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i84: /* x=84 */ q = 0.09402 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i85: /* x=85 */ q = 0.1031 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i86: /* x=86 */ q = 0.1144 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i87: /* x=87 */ q = 0.12669 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i88: /* x=88 */ q = 0.14002 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i89: /* x=89 */ q = 0.15444 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i90: /* x=90 */ q = 0.16997 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i91: /* x=91 */ q = 0.18666 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i92: /* x=92 */ q = 0.20452 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i93: /* x=93 */ q = 0.22357 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i94: /* x=94 */ q = 0.24383 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i95: /* x=95 */ q = 0.26527 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i96: /* x=96 */ q = 0.28789 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i97: /* x=97 */ q = 0.31166 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i98: /* x=98 */ q = 0.33653 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i99: /* x=99 */ q = 0.36245 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i100: /* x=100 */ q = 0.38934 + addrisk; ret_rbw += p * vn_precomputed[i]; ret_abw += p * q * vn_precomputed[++i]; p *= (1-q); if (i>=n) goto end; i101: /* x=101 */ *rbw = ret_rbw + p * vn_precomputed[i]; *abw = ret_abw + p * vn_precomputed[i+1]; *ebw = 0; return; end: *ebw = p * vn_precomputed[n]; *abw = ret_abw; *rbw = ret_rbw; } static void barwert(int x, int gender, double irate, double addrisk, int n, double *abw, double *ebw, double *rbw) { if (n==0) { *abw=0; *rbw=0; *ebw=1; } else if (x>100) { *abw=vn(1); *rbw=1; *ebw=0; } else { if (mortality_max[gender] + addrisk <= 1) { if (gender==0) { bw_m(x, n, addrisk, abw, ebw, rbw); } else { bw_f(x, n, addrisk, abw, ebw, rbw); } } else { barwert_common(x, gender, irate, addrisk, n, abw, ebw, rbw); } } } static void barwert_addrisk0(int x, int gender, double irate, int n, double *abw, double *ebw, double *rbw) { int i; double p=1; double q; *abw = 0; *rbw = 0; int over100 = (MAXAGE + 1) - x; int top = over100 < n ? over100 : n; /* nAx, aexn */ for (i=0; i < top; i++) { q = qx_addrisk0(x+i, gender); *abw += p * q * vn(i+1); *rbw += p * vn(i); p *= (1-q); } // skip loop until `n', because in the next steps `p' would be zero anyways if (i < n) { *abw += p * vn(i+1); *rbw += p * vn(i); p = 0; } /* nEx */ *ebw = p * vn(n); } static void barwert_addrisk0_fromCache(int x, int gender, double irate, int n, double *abw, double *ebw, double *rbw) { int ind_cache; struct_barwert_addrisk0_cache *pcache; struct_barwert_result *presult; for (ind_cache=0; ind_cache<2; ind_cache++) { pcache = &barwert_caches[ind_cache]; if (pcache->irate==irate) { presult = &(pcache->results[gender][x][n]); *abw = presult->abw; *ebw = presult->ebw; *rbw = presult->rbw; return; } } precompute_vn_irate(irate, n); barwert_addrisk0(x, gender, irate, n, abw, ebw, rbw); } static void precompute_barwert_addrisk0() { int ind_cache; double irate_arr[2] = { 0.025, 0.035 }; double irate; struct_barwert_addrisk0_cache *pcache; struct_barwert_result *presults; int gender, age, n; for (ind_cache=0; ind_cache<2; ind_cache++) { pcache = &(barwert_caches[ind_cache]); irate = irate_arr[ind_cache]; pcache->irate = irate; precompute_vn_irate(irate, MAXAGE-1); for (gender=0; gender<=1; gender++) { for (age=0; age<=130; age++) { for (n=0; n<=50; n++) { presults = &(pcache->results[gender][age][n]); barwert_addrisk0(age, gender, irate, n, &(presults->abw), &(presults->ebw), &(presults->rbw)); } } } } } static double doit_common(int gender, int age, int n, double irate, double addrisk, double vsum, double* res_out) { int t; double gamma = 0.004; double alpha = 0.02; double res; double abw, ebw, rbw; double premnorm; double prem; double totalsum; precompute_vn_irate(irate, n); barwert(age, gender, irate, addrisk, n, &abw, &ebw, &rbw); /* compute premium */ premnorm = (abw + ebw + gamma*rbw) / (rbw - alpha); prem = vsum * premnorm; totalsum = prem; /* compute reserve values over time */ for (t=0; t<=n; t++) { barwert(age+t, gender, irate, addrisk, n-t, &abw, &ebw, &rbw); res = abw + ebw; if (t1e9) { fprintf(stdout, "reset, i=%d, totalsum=%.15Lf\n", i, totalsum); totalsum=0; } totalsum += ret; } totalsum += doit(0, 50, 50, 0.04, 0.70, 100000, res); totalsum += doit(1, 60, 50, 0.02, 0.69, 100000, res); totalsum += doit(1, 0, 40, 0.03, 0.0, 100000, res); clockEnd = clock(); fprintf(stdout, "totalsum = %.15Lf\n", totalsum); fprintf(stderr, "totalsum = %.15Lf\n", totalsum); fprintf(stderr, "took %ld ms\n", (clockEnd - clockStart) / (CLOCKS_PER_SEC / 1000)); return 0; }