/* pi_temp2volt_K( temp, vref ) -- Convert temperature to voltage, K-type * @temp -- Temperature in deg C * @vref -- Optional reference voltage to scale the result * (eg. Use 0.001 for result in mV) * -------- * Returns "raw" reading expressed as a ratio of vref (may exceed [0,1) ) */ int pi_temp2volt_K(lua_State * L) { lua_Number temp ; lua_Number vref ; lua_Number reading ; temp = luaL_checknumber( L, 1 ); vref = luaL_optnumber( L, 2, 1.0 ); if( temp < negTempLIMIT || temp > posTempLIMIT ) { #ifdef RANGE2ERROR return luaL_error( L, "bad argument #1 to temp2volt_K (out of range [%g, %g] degC)", negTempLimit, posTempLIMIT ); #else lua_pushnumber( L, NAN ); return 1 ; #endif } if( temp < 0 ) { reading = evalPoly( temp, negTemp, sizeof(negTemp)/sizeof(*negTemp)-1, NULL ); } else { reading = evalPoly( temp, posTemp, sizeof(posTemp)/sizeof(*posTemp)-1, &posTempAdj ); } reading /= 1000.0 * vref ; /* to Volts/Vref */ lua_pushnumber( L, reading ); return 1 ; }
/* pi_volt2temp_K( reading, vref ) -- Convert voltage to temp, K-type * @reading -- "raw" reading expressed as a fraction [0,1) of vref * @vref -- Optional Vref for this reading (default 1.0) * eg. Use 0.001 for result already in mV or 2.048 for * "raw" reading as a fraction of Vref at 2.048 Volts * -------- * Returns temperature in deg C */ int pi_volt2temp_K(lua_State * L) { lua_Number reading ; lua_Number vref ; lua_Number temp ; reading = luaL_checknumber( L, 1 ); vref = luaL_optnumber( L, 2, 1.0 ); reading *= vref * 1000.0 ; /* to milli-Volts */ if( reading < invNegmVLIMIT || reading > invPosmVLIMIT ) { #ifdef RANGE2ERROR return luaL_error( L, "bad arguments #1*#2 to volt2temp_K, out of range [%g, %g] mVolts", invNegmVLIMIT, invPosmVLIMIT ); #else lua_pushnumber( L, NAN ); return 1 ; #endif } if( reading < 0 ) { temp = evalPoly( reading, invNegmV, sizeof(invNegmV)/sizeof(*invNegmV)-1, NULL ); } else { temp = evalPoly( reading, invPosmV, sizeof(invPosmV)/sizeof(*invPosmV)-1, NULL ); } lua_pushnumber( L, temp ); return 1 ; }
QImage* RGBPtm::createPreview(int width, int height) { // Computes the height and the width of the preview. int level = 3; int imageH = mipMapSize[3].height(); int imageW = mipMapSize[3].width(); for (int i = 0; i < 4; i++) { if (mipMapSize[i].width() <= width || mipMapSize[i].height() <= height) { if (mipMapSize[i].width() < width && mipMapSize[i].height() < height && i > 0) i--; imageH = mipMapSize[i].height(); imageW = mipMapSize[i].width(); level = i; break; } } // Creates the preview. unsigned char* buffer = new unsigned char[imageH*imageW*4]; const PTMCoefficient* redPtr = redCoefficients.getLevel(level); const PTMCoefficient* greenPtr = greenCoefficients.getLevel(level); const PTMCoefficient* bluePtr = blueCoefficients.getLevel(level); int offset = 0; for (int i = 0; i < imageH; i++) { for (int j = 0; j < imageW; j++) { offset = i * imageW + j; buffer[offset*4 + 2] = tobyte(evalPoly((int*)&(redPtr[offset][0]), 0, 0)); buffer[offset*4 + 1] = tobyte(evalPoly((int*)&(greenPtr[offset][0]), 0, 0)); buffer[offset*4 + 0] = tobyte(evalPoly((int*)&(bluePtr[offset][0]), 0, 0)); buffer[offset*4 + 3] = 255; } } QImage* image = new QImage(buffer, imageW, imageH, QImage::Format_RGB32); return image; }
int main() { Polynome p = calloc(3, sizeof(int)); // p = 2 + 3x + 5x^2 p[0] = 2; p[1] = 3; p[2] = 5; float result = evalPoly(p, 3, 4.5); printf("p(x) = %d + %dx + %dx^2\np(4.5) = %g\n", p[0], p[1], p[2], result); return 0; }
int main(void) { int leaderTerm = 0, n = 0; printf("input the max leader term: "); if (!scanf("%d", &leaderTerm)) { puts("It's not a real leader term input."); exit(1); } int *poly[4] = { new int[leaderTerm + 1], new int[leaderTerm + 1], new int[leaderTerm + 1], new int[leaderTerm + 1] }; for(int i = 0; i < 2; i++) { puts(""); printf("please input the detail of polynomial %c\n", "AB"[i]); usrInputPoly(poly[i], leaderTerm); printf("this is your polynomial %c\n", "AB"[i]); polyDisplay(poly[i], leaderTerm); } puts(""); puts("this is the sum of polynomial A and B:"); for(int i = leaderTerm; (i + 1); i--) *(poly[2] + i) = *(poly[0] + i) + *(poly[1] + i); polyDisplay(poly[2], leaderTerm); puts("this is the difference between polynomial A and B:"); for(int i = leaderTerm; (i + 1); i--) *(poly[2] + i) = *(poly[0] + i) - *(poly[1] + i); polyDisplay(poly[2], leaderTerm); puts(""); printf("give a number as n: "); if (!scanf("%d", &n)) { puts("It's not a real n input."); exit(1); } for(int i = 0; i < 2; i++) printf ( "value of polynomial %c is %i\n", "AB"[i], evalPoly(poly[i],leaderTerm, n) ); return 0; }
double canonEmbedMax(const ZZX& f, const FHEcontext& context) { complex<double> val; double nval, res; long m = context.zMstar.M(); res = 0.0; for (long i = 0; i < m; i++) { if (context.zMstar.inZmStar(i)) { val = evalPoly(f, i, m); nval = norm(val); if (nval > res) res = nval; } } return res; }
int main(){ int n = 0; double complex c[20]; double a, b; while (scanf("%lf %lf", &a, &b) == 2) c[n++] = a + b*I; double complex guess[n]; double cZmax = 0; double complex cZ[n]; double theta = 2*M_PI/n; float R = 1 + max(n, c); printf("iter 1\n"); for (int j = 0; j<n; j++){ guess[j] = ((cos(j*theta) + I * sin(j*theta)) * (R)); printf("z[%i] = %0.10f + %0.10f i\n", j, creal(guess[j]), cimag(guess[j])); } for (int k=1; k < 50; k++){ cZmax = 0; for(int j=0; j<n; j++){ cZ[j] = -1 * evalPoly(n, c, guess[j]) / Q(n, guess, j); //printf("------%0.10f + %0.10fi\n", creal(cZ[j]),cimag(cZ[j])); if (cabs(cZ[j]) > cZmax) cZmax = cabs(cZ[j]); } for (int j=0; j <n; j++) guess[j] += cZ[j]; if(cZmax <= FLT_EPSILON) break; printf("iter %i\n",k+1); for(int j=0; j<n; j++) printf("z[%i] = %0.10f + %0.10f i\n", j, creal(guess[j]), cimag(guess[j])); } // printf("%0.10f + %0.10fi\n", creal(guess[j]),cimag(guess[j])); return 0; }
int RGBPtm::createImage(unsigned char** buffer, int& width, int& height, const vcg::Point3f& light, const QRectF& rect, int level, int mode) { #ifdef PRINT_DEBUG QTime first = QTime::currentTime(); #endif // Computes height and width of the texture. width = ceil(rect.width()); height = ceil(rect.height()); int offx = rect.x(); int offy = rect.y(); if (currentRendering != DETAIL_ENHANCEMENT || mode == LUMR_MODE || mode == LUMG_MODE || mode == LUMB_MODE) { for (int i = 0; i < level; i++) { width = ceil(width/2.0); height = ceil(height/2.0); offx = offx/2; offy = offy/2; } } (*buffer) = new unsigned char[width*height*4]; int offsetBuf = 0; if (mode == LUMR_MODE || mode == LUMG_MODE || mode == LUMB_MODE) { // Creates map of the RGB component. const PTMCoefficient* coeffPtr = NULL; switch(mode) { case LUMR_MODE: coeffPtr = redCoefficients.getLevel(level); break; case LUMB_MODE: coeffPtr = greenCoefficients.getLevel(level); break; case LUMG_MODE: coeffPtr = blueCoefficients.getLevel(level); break; } for (int y = offy; y < offy + height; y++) { for (int x = offx; x < offx + width; x++) { int offset = y * mipMapSize[level].width() + x; unsigned char c = tobyte(evalPoly((int*)&(coeffPtr[offset][0]), light.X(), light.Y())); (*buffer)[offsetBuf + 0] = c; (*buffer)[offsetBuf + 1] = c; (*buffer)[offsetBuf + 2] = c; (*buffer)[offsetBuf + 3] = 255; offsetBuf += 4; } } } else { // Applies the current rendering mode. RenderingInfo info = {offx, offy, height, width, level, mode, light, 6}; list->value(currentRendering)->applyPtmRGB(redCoefficients, greenCoefficients, blueCoefficients, mipMapSize, normals, info, (*buffer)); } #ifdef PRINT_DEBUG QTime second = QTime::currentTime(); double diff = first.msecsTo(second) / 1000.0; if (mode == DEFAULT_MODE) { switch(currentRendering) { case DEFAULT: printf("Default rendering: %.5f s\n", diff); break; case NORMALS: printf("Normals: %.5f s\n", diff); break; case DIFFUSE_GAIN: printf("Diffuse gain: %.5f s\n", diff); break; case SPECULAR_ENHANCEMENT: printf("Specular enhancement: %.5f s\n", diff); break; case NORMAL_ENHANCEMENT: printf("Normal enhancement: %.5f s\n", diff); break; case UNSHARP_MASKING_IMG: printf("Unsharp masking image: %.5f s\n", diff); break; case UNSHARP_MASKING_LUM: printf("Unsharp masking luminance: %.5f s\n", diff); break; case COEFF_ENHANCEMENT: printf("Coefficient enhancement: %.5f s\n", diff); break; case DETAIL_ENHANCEMENT: printf("Detail enhancement: %.5f s\n", diff); break; case DYN_DETAIL_ENHANCEMENT: printf("Dynamic detail enhancement: %.5f s\n", diff); break; } } else printf("Browing mode: %.5f s\n", diff); #endif return 0; }
/** * Prints 'Yes' if X and Y represent the same multiset of lines. * 'No' otherwise. Under the assumption that a line consists of * at most 80 characters, and each character is represented by * at most 16 bits, so each element in the multiset is represented * by at most b = 80*16 = 1280 bits and a multiset contains at most * n <= 2^24 lines this algorithm outputs correctly with probability * 1-n/2147483647 * * @param[in] argc The number of command line arguments * @param[in] argv A pointer to an array of string where: * There must be exactly 3 arguments where: * -- The first argument is data-file-1 (X) * -- The second argument is data-file-2 (Y) * -- A user seed in base 10 * @return Exit code 0 on success, 1 otherwise */ int main(int argc, char *argv[]) { FILE *fp1, *fp2; //!< file pointers long fSize; //!< file size (in bytes) long numChar; //!< number of chars in file unsigned char *buffer; //!< buffer with the whole file unsigned long a[2*80]; //!< mapping from 2^16 to Fp unsigned long w[2]; //!< used to evaulate polynomial unsigned long f1[2], f2[2]; //!< fingerprint of file 1 and 2 /* Initialize Mersenne Twister */ init_mt(argv[3]); /* Initialize a and w */ setAW(a, w); /* Open first file */ if((fp1 = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "Cannot open data-file-1\n"); exit(1); } /* Get the file size */ fseek(fp1, 0, SEEK_END); fSize = ftell(fp1); numChar = fSize/sizeof(unsigned char); rewind(fp1); /* Read the whole file into buffer */ buffer = (unsigned char *) malloc(sizeof(unsigned char)*(fSize)); if(fread(buffer, sizeof(unsigned char), fSize, fp1) != fSize) { fprintf(stderr, "Could not read data-file-1\n"); exit(1); } /* Close data files (We are done with them!) */ fclose(fp1); /* Fingerprint of data-file-1 */ evalPoly(buffer, numChar, w, a, f1); /* Open second file */ if((fp2 = fopen(argv[2], "r")) == NULL) { fprintf(stderr, "Cannot open data-file-2\n"); exit(1); } /* Read the whole file into (previus) buffer */ if(fread(buffer, sizeof(unsigned char), fSize, fp2) != fSize) { fprintf(stderr, "Could not read data-file-2\n"); exit(1); } /* Close the file */ fclose(fp2); /* Fingerprint of data-file-2 */ evalPoly(buffer, numChar, w, a, f2); /* * We have the following cases: * - f1[0] - f2[0] == 0 and f1[1] - f2[1] != 0: 1st was false positive * - f1[0] - f2[0] != 0 and f1[1] - f2[1] == 0: 2nd was false positive * - f1[0] - f2[0] != 0 and f1[1] - f2[1] != 0: They are distinct * - f1[0] - f2[0] == 0 and f1[1] - f2[1] == 0: They are probably equal */ if(((f1[0] - f2[0]) == 0) && ((f1[1] - f2[1]) == 0)) { printf("Yes"); //<- With prob. 1-2^-12 } else { printf("No"); } /* Cleanup */ free(buffer); return 0; }
ossim_float64 ossimAlphaSensorHSI::getScanAngle(const ossim_float64& line) const { ossim_float64 scanAngle = evalPoly(m_scanPoly, line); return scanAngle; }