summaryrefslogtreecommitdiff
path: root/lib/convex.c
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2017-11-03 15:56:35 -0400
committerJaron Kent-Dobias <jaron@kent-dobias.com>2017-11-03 15:56:35 -0400
commit181db84a8ffb26e436a43bb268fe5ef060206e66 (patch)
tree25e04455ed47daa760f3fadf8aae4ddaa679c192 /lib/convex.c
parentc93a56cb0b5e52242667b918a6800384498b9b12 (diff)
downloadc++-181db84a8ffb26e436a43bb268fe5ef060206e66.tar.gz
c++-181db84a8ffb26e436a43bb268fe5ef060206e66.tar.bz2
c++-181db84a8ffb26e436a43bb268fe5ef060206e66.zip
add last term to the convex function
Diffstat (limited to 'lib/convex.c')
-rw-r--r--lib/convex.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/convex.c b/lib/convex.c
index 4816aeb..096504d 100644
--- a/lib/convex.c
+++ b/lib/convex.c
@@ -66,22 +66,28 @@ double *get_convex_minorant(uint64_t n, double *Gammas) {
pos = L;
- double *g = (double *)calloc(n, sizeof(double));
+ double *g = (double *)calloc(n + 1, sizeof(double));
double rho = 0;
- for (uint64_t i = 0; i < n; i++) {
+ for (uint64_t i = 0; i < n + 1; i++) {
if (i > pos->next->p->x) {
pos = pos->next;
}
g[i] = pos->p->y + ((double)i - (double)(pos->p->x)) * (pos->next->p->y - pos->p->y) / ((double)(pos->next->p->x) - (double)(pos->p->x));
- if (Gammas[i] - g[i] > rho) {
- rho = Gammas[i] - g[i];
+ if (i <n) {
+ if (Gammas[i] - g[i] > rho) {
+ rho = Gammas[i] - g[i];
+ }
+ } else {
+ if (0 - g[i] > rho) {
+ rho = 0 - g[i];
+ }
}
}
- for (uint64_t i = 0; i < n; i++) {
+ for (uint64_t i = 0; i < n + 1; i++) {
g[i] += rho / 2;
}