#include #include #include #include /* life insurance calculation */ static int mortality_male[101] = { 744, 46, 31, 22, 19, 20, 20, 18, 17, 17 , 17, 18, 19, 23, 29, 36, 46, 59, 75, 90 , 103, 111, 114, 113, 112, 115, 120, 126, 132, 139 , 147, 158, 171, 187, 205, 224, 244, 264, 287, 313 , 344, 381, 427, 478, 535, 596, 659, 725, 793, 867 , 946, 1030, 1119, 1211, 1306, 1402, 1503, 1613, 1733, 1865 , 2008, 2162, 2326, 2500, 2687, 2889, 3105, 3340, 3592, 3864 , 4159, 4479, 4824, 5197, 5597, 6034, 6513, 7049, 7668, 8373 , 9149, 9993, 10823, 11645, 12476, 13228, 14256, 15356, 16530, 17781 , 19112, 20526, 22024, 23608, 25279, 27037, 28883, 30816, 32834, 34935 , 37116 }; static int mortality_female[101] = { 615, 33, 24, 18, 16, 14, 12, 11, 11, 12 , 12, 12, 13, 15, 18, 23, 27, 28, 27, 28 , 29, 29, 27, 26, 26, 28, 30, 32, 35, 37 , 40, 43, 46, 50, 55, 60, 67, 75, 85, 97 , 112, 129, 148, 169, 191, 214, 237, 263, 290, 319 , 351, 384, 418, 453, 489, 527, 568, 611, 657, 706 , 758, 815, 880, 953, 1036, 1131, 1238, 1360, 1501, 1666 , 1856, 2076, 2323, 2603, 2921, 3282, 3695, 4171, 4724, 5357 , 6060, 6840, 7650, 8499, 9402, 10310, 11440, 12669, 14002, 15444 , 16997, 18666, 20452, 22357, 24383, 26527, 28789, 31166, 33653, 36245 , 38934 }; #define GENDER_MALE 0 #define GENDER_FEMALE 1 static int *mortality[] ={ mortality_male, mortality_female }; static double vn_precomputed[100]; 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) { if (x>100) { return 1; } double q = (double) mortality[gender][x] / 100000.0 + addrisk; return q > 1 ? 1 : q; } #if 0 static double px(int x, int gender, double addrisk) { return (1 - qx(x, gender, addrisk)); } #endif #if 0 static double npx(int x, int gender, double addrisk, int n) { int t; double p=1; for (t=0; t1e9) { fprintf(stdout, "reset, i=%d, totalsum=%.15Lf\n", i, totalsum); totalsum=0; } totalsum += ret; } 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; }