gcdpoly.cc.txt
来自「压缩文件中是Error Correction Coding - Mathemat」· 文本 代码 · 共 66 行
TXT
66 行
// gcd.cc --- Implement a gcd algorithm for a general// polynomial type. Also, implement a gcd for polynomials with real// coefficients, truncating coefficients as necessary to avoid// roundoff problems.//// Also, implement the Sugiyama algorithm // Copyright 2004 by Todd K. Moon// Permission is granted to use this program/data// for educational/research only#include <math.h>#include "polynomialT.h"// declare the gcd function, setting up a default value for the rdegtemplate <class T> voidgcd(const polynomialT<T> &a, const polynomialT<T> &b, polynomialT<T> &g, polynomialT<T> &s, polynomialT<T> &t, int rdeg=0);// Function definition: gcdtemplate <class T> voidgcd(const polynomialT<T> &a, const polynomialT<T> &b, polynomialT<T> &g, polynomialT<T> &s, polynomialT<T> &t, int rdeg){ // Fill in the blanks ...}static void chop(polynomialT<double> *p, double eps);// This is a specialization for doubles, since it has to handle// the roundoff more carefullytemplate <> voidgcd(const polynomialT<double> &a, const polynomialT<double> &b, polynomialT<double> &g, polynomialT<double> &s, polynomialT<double> &t, int rdeg){ // Fill in the blanks.}void chop(polynomialT<double> *p, double eps){ int i; int newdegree=0; int done = 0; for(i = p->getdegree(); i>= 0; i--) { if(fabs((*p)[i]) < eps) { (*p)[i] = 0; if(i== p->getdegree()) { newdegree = i; // set that new degree is necessary } } } if(newdegree) { for(i = newdegree-1; i > 0; i--) { if((*p)[i] != 0) { p->resizecopy(i); done = 1; break; } } if(!done) p->resizecopy(0); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?