/* * MathPlanner 3.2 - Mathematical design tool. * Copyright(C) 2003 Jarmo Nikkanen * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation. * * You should have received a copy of the GNU General Public License with this program. * */ // RATIONAL MATH #include "MathHeaders.h" #include #include "Error.h" mpl_real *table_of_numbers=NULL; mpl_real per_table[30]; int count_of_numbers=0; mpl_real mpl_rat2real(mpl_rational a) { return(a.a/a.b); } mpl_rational mpl_power(mpl_rational a,mpl_real n) { mpl_rational v; v.a=pow(a.a,n); v.b=pow(a.b,n); return(v); } mpl_rational mpl_decrade(mpl_rational r) { mpl_rational c; int i; mpl_real n,up=r.a,lo=r.b; if (table_of_numbers) { for(i=0;i70) for(i=0,k=18;i<12;i++,k+=3) { per_table[10+i]=60.0*table_of_numbers[k]*table_of_numbers[k+1]*table_of_numbers[k+2]; } else ErrorReport("Mathematics","Table too small"); return(true); } void delete_table_of_numbers() { if (table_of_numbers) free(table_of_numbers); count_of_numbers=0; } bool create_root(mpl_real real,mpl_real *in,mpl_real *out) { int i,count; mpl_real n; if (real<1) return(false); if (table_of_numbers && count_of_numbers>0) { *in=1.0; *out=1.0; for(i=0;iroot=false; info->pii_location=0; if (id==1) info->pii_location=1; if (id==2) info->pii_location=2; if (id==3) info->root=true; if (id==4) info->pii_location=1,info->root=true; if (id==5) info->pii_location=2,info->root=true; } if (table_of_numbers && count_of_numbers>70) for(i=0;i<70;i++) { n=table_of_numbers[i]; while (fmod(up,n)==0 && fmod(lo,n)==0) { up/=n; lo/=n; } if (n>up && n>lo) break; } else ErrorReport("Mathematics","No table"); rat->a=up; rat->b=lo; return(true); }