Ejemplo n.º 1
0
int main(void){
    double principal, interest_rate, monthly, total_paid;
    int   years;


    printf("Enter your principal: ");
    scanf("%lf", &principal);
    printf("Enter your interest rate: ");
    scanf("%lf", &interest_rate);
    printf("Enter your term in years: ");
    scanf("%d", &years);

    // Using nicely formatted numbers to return figures
    monthly = calc_monthly(principal, interest_rate, years);
    printf("Your monthly payment is: %.2lf\n", monthly);

    total_paid = calc_total(monthly, years);

    printf("Your total payment over %d months will be: %.2lf\n", years*12, total_paid);
    printf("You will pay %.2lf total in interest\n", (total_paid-principal));
    return 0;
}
Ejemplo n.º 2
0
void view_curses(struct xxxid_stats *cs, struct xxxid_stats *ps)
{
    if (!stdscr)
    {
        initscr();
        keypad(stdscr, TRUE);
        nonl();
        cbreak();
        noecho();
        curs_set(FALSE);
        nodelay(stdscr, TRUE);
    }

    int diff_len = 0;

    struct xxxid_stats *diff = create_diff(cs, ps, &diff_len);
    struct xxxid_stats *s;

    double total_read, total_write;
    char *str_read, *str_write;

    calc_total(diff, &total_read, &total_write);

    humanize_val(&total_read, &str_read);
    humanize_val(&total_write, &str_write);

    mvprintw(0, 0, HEADER_FORMAT,
             total_read,
             str_read,
             total_write,
             str_write
            );

#define SORT_CHAR(x) ((sort_by == x) ? (sort_order == SORT_ASC ? '<' : '>') : ' ')
    attron(A_REVERSE);
    mvhline(1, 0, ' ', 1000);
    mvprintw(1, 0, "%5s%c %4s%c  %6s%c   %11s%c %11s%c %6s%c %6s%c %s%c",
             config.f.processes ? "PID" : "TID", SORT_CHAR(SORT_BY_PID),
             "PRIO", SORT_CHAR(SORT_BY_PRIO),
             "USER", SORT_CHAR(SORT_BY_USER),
             "DISK READ", SORT_CHAR(SORT_BY_READ),
             "DISK WRITE", SORT_CHAR(SORT_BY_WRITE),
             "SWAPIN", SORT_CHAR(SORT_BY_SWAPIN),
             "IO", SORT_CHAR(SORT_BY_IO),
             "COMMAND", SORT_CHAR(SORT_BY_COMMAND)
            );
    attroff(A_REVERSE);

    sort_diff(diff);

    int line = 2;
    for (s = diff; s; s = s->__next, line++)
    {
        struct passwd *pwd = getpwuid(s->euid);

        double read_val = s->read_val;
        double write_val = s->write_val;

        if (config.f.only && (!read_val || !write_val))
            continue;

        char *read_str, *write_str;

        if (config.f.kilobytes)
        {
            read_val /= 1000;
            write_val /= 1000;
            read_str = config.f.accumulated ? "K" : "K/s";
            write_str = config.f.accumulated ? "K" : "K/s";
        }
        else
        {
            humanize_val(&read_val, &read_str);
            humanize_val(&write_val, &write_str);
        }

        mvprintw(line, 0, "%5i  %4s  %-9.9s  %7.2f %-3.3s  %7.2f %-3.3s %5.2f %% %5.2f %%  %s\n",
                 s->tid,
                 str_ioprio(s->io_prio),
                 pwd ? pwd->pw_name : "UNKNOWN",
                 read_val,
                 read_str,
                 write_val,
                 write_str,
                 s->swapin_val,
                 s->blkio_val,
                 s->cmdline
                );
    }
    free(diff);
    refresh();
}
Ejemplo n.º 3
0
void view_batch(struct xxxid_stats *cs, struct xxxid_stats *ps)
{
    int diff_len = 0;

    struct xxxid_stats *diff = create_diff(cs, ps, &diff_len);
    struct xxxid_stats *s;

    double total_read, total_write;
    char *str_read, *str_write;

    calc_total(diff, &total_read, &total_write);

    humanize_val(&total_read, &str_read);
    humanize_val(&total_write, &str_write);

    printf(HEADER_FORMAT,
           total_read,
           str_read,
           total_write,
           str_write
          );

    if (config.f.timestamp)
    {
        time_t t = time(NULL);
        printf(" | %s", ctime(&t));
    }
    else
        printf("\n");

    if (!config.f.quite)
        printf("%5s %4s %8s %11s %11s %6s %6s %s\n",
               config.f.processes ? "PID" : "TID",
               "PRIO",
               "USER",
               "DISK READ",
               "DISK WRITE",
               "SWAPIN",
               "IO",
               "COMMAND"
              );

    for (s = diff; s; s = s->__next)
    {
        struct passwd *pwd = getpwuid(s->euid);

        double read_val = s->read_val;
        double write_val = s->write_val;

        if (config.f.only && (!read_val || !write_val))
            continue;

        char *read_str, *write_str;

        if (config.f.kilobytes)
        {
            read_val /= 1000;
            write_val /= 1000;
            read_str = config.f.accumulated ? "K" : "K/s";
            write_str = config.f.accumulated ? "K" : "K/s";
        }
        else
        {
            humanize_val(&read_val, &read_str);
            humanize_val(&write_val, &write_str);
        }

        printf("%5i %4s %-10.10s %7.2f %-3.3s %7.2f %-3.3s %2.2f %% %2.2f %% %s\n",
               s->tid,
               str_ioprio(s->io_prio),
               pwd ? pwd->pw_name : "UNKNOWN",
               read_val,
               read_str,
               write_val,
               write_str,
               s->swapin_val,
               s->blkio_val,
               s->cmdline
              );
    }

    free(diff);
}
Ejemplo n.º 4
0
static void verify_group(const char *provider,
                         unsigned char n_max, signed char ml_max) {
    const size_t count = calc_total(n_max, ml_max);
    struct clh2_indicesp *ixs;
    const double *zs, *ws = NULL;
    size_t num_nonzero = 0, num_order3 = 0, num_order4 = 0, num_order5 = 0,
           i = 0;
    unsigned char n1, n2, n3, n4;
    signed char ml1, ml2, ml3, ml4;

    printf("group (%u, %d):\n", n_max, ml_max);
    fflush(stdout);

    ixs = (struct clh2_indicesp *) malloc(sizeof(*ixs) * count);
    if (!ixs)
        ensure(ENOMEM);

    for (n1 = 0; n1 < n_max; ++n1)
    for (n2 = 0; n2 < n_max; ++n2)
    for (n3 = 0; n3 < n_max; ++n3)
    for (n4 = 0; n4 < n_max; ++n4)
    for (ml1 = (signed char) (-ml_max + 1); ml1 < ml_max; ++ml1)
    for (ml2 = (signed char) (-ml_max + 1); ml2 < ml_max; ++ml2)
    for (ml3 = (signed char) (-ml_max + 1); ml3 < ml_max; ++ml3) {
        ml4 = (signed char) (ml1 + ml2 - ml3);
        ixs[i].n1  = n1;
        ixs[i].ml1 = ml1;
        ixs[i].n2  = n2;
        ixs[i].ml2 = ml2;
        ixs[i].n3  = n3;
        ixs[i].ml3 = ml3;
        ixs[i].n4  = n4;
        ixs[i].ml4 = ml4;
        ++i;
    }

    ensure(clh2_request(&zs, provider, count, ixs));
    if (clh2_request(&ws, provider_ref, count, ixs))
        no_ref = 1;

    for (i = 0; i != count; ++i) {
        const double z = zs[i];
        if (ws)
            verify(&ixs[i], z, ws[i]);
        if (z > abserr)
            ++num_nonzero;
        if (1e-3 <= z && z < 1e-2)
            ++num_order3;
        if (1e-4 <= z && z < 1e-3)
            ++num_order4;
        if (1e-5 <= z && z < 1e-4)
            ++num_order5;
    }

    clh2_free(count, zs);
    clh2_free(count, ws);

    printf(
        "----------------------------------------\n"
        "total:   ~%.8g\n"
        "nonzero: %2.2f%% (excluding nonconserving elements)\n"
        "  1e-3 to 1e-2:  %2.2f%% \n"
        "  1e-4 to 1e-3:  %2.2f%% \n"
        "  1e-5 to 1e-4:  %2.2f%% \n"
        "----------------------------------------\n",
        (double) count,
        (double) num_nonzero * 100. / (double) count,
        (double) num_order3 * 100. / (double) count,
        (double) num_order4 * 100. / (double) count,
        (double) num_order5 * 100. / (double) count
    );
}