/*
 * Auto Payment Calculator V1.0.1beta
 * Copyright (C) 1997  Eric A. Griff
 *
 * An Auto Payment Calculator.
 *
 * *Portions of this code use xforms-0.86 which is copyrighted as
 *
 *    Copyright (C) 1996-1997 by T.C. Zhao and Mark Overmars. ALL RIGHTS 
 *      RESERVED
 *
 */

#include "mathfun.h"

double
pmt(principal,rate,term)
        double principal;
        float rate;
        int term;
{
        double pmnt;
        rate = (float) (((int)(rate*1000000.0))/1000000.0);
        pmnt = (principal * ((double)rate)) / (1 - powf((1+rate), -((float)term)));

#ifdef FOUR
        pmnt = ((int)(pmnt * 10000.0))/10000.0;
#else
        pmnt = ((int)(pmnt * 100.0))/100.0;
#endif
        return pmnt;
}

double
wpmt(principal,rate,months)
        double principal;
        double rate;
        int months;
{
        int numPayments;
        double payment;
        double perPaymentRate;

        numPayments = (int)((((float)months)*4.3333333)+.5);
        fweeks = numPayments;
        perPaymentRate = (((float)rate)/52)*.01;
        payment = pmt(principal,perPaymentRate,numPayments);
        return payment;
}

double
mpmt(principal,rate,months)
        double principal;
        double rate;
        int months;
{
        return pmt(principal,(((float)rate)/12)*.01,months);
}



syntax highlighted by Code2HTML, v. 0.9.1