int cxrec (struct cxpr z, struct cxpr *w) { struct xpr x; int sa, sb, ea, eb; if (xprcmp (&z.re, &xZero) == 0 && xprcmp (&z.im, &xZero) == 0) return 0; else { sa = z.re.nmm[0] & xM_sgn; sb = z.im.nmm[0] & xM_sgn; ea = (z.re.nmm[0] &= xM_exp) - xBias; eb = (z.im.nmm[0] &= xM_exp) - xBias; if (ea > eb + XBOUND) x = z.re; else if (eb > ea + XBOUND) x = z.im; else { z.re.nmm[0] -= eb; z.im.nmm[0] = xBias; x = xsqrt (xadd (xmul (z.re, z.re), xmul (z.im, z.im), 0)); x.nmm[0] += eb; z.re.nmm[0] += eb; z.im.nmm[0] += eb; } w->re = xdiv (xdiv (z.re, x), x); w->im = xdiv (xdiv (z.im, x), x); w->re.nmm[0] |= sa; w->im.nmm[0] |= xM_sgn ^ sb; return 1; } }
struct xpr cxarg (struct cxpr z) { int rs, is; rs = xsgn (&z.re); is = xsgn (&z.im); if (rs > 0) return xatan (xdiv (z.im, z.re)); else if (rs < 0) { z.re.nmm[0] ^= xM_sgn; z.im.nmm[0] ^= xM_sgn; if (is >= 0) return xadd (xPi, xatan (xdiv (z.im, z.re)), 0); else return xadd (xatan (xdiv (z.im, z.re)), xPi, 1); } else /* z.re is zero ! */ { if (!xsigerr (is == 0, XEDOM, "cxarg()")) return (is > 0 ? xPi2 : xneg (xPi2)); else return xneg (xPi2); /* Dummy value :) */ } }
struct xpr xtan (struct xpr z) { int k, m; z = rred (z, 't', &k); if ((xsigerr (xprcmp (&z, &xPi2) >= 0, XEDOM, "xtan()"))) return (!k ? xPinf : xMinf); else { if (xprcmp (&z, &xPi4) == 1) { m = 1; z = xadd (xPi2, z, 1); } else m = 0; if ((k)) z = xneg (c_tan (z)); else z = c_tan (z); if (m) return xdiv (xOne, z); else return z; } }
void cacheDigestReport(CacheDigest * cd, const char *label, StoreEntry * e) { CacheDigestStats stats; assert(cd && e); cacheDigestStats(cd, &stats); storeAppendPrintf(e, "%s digest: size: %d bytes\n", label ? label : "", stats.bit_count / 8 ); storeAppendPrintf(e, "\t entries: count: %d capacity: %d util: %d%%\n", cd->count, cd->capacity, xpercentInt(cd->count, cd->capacity) ); storeAppendPrintf(e, "\t deletion attempts: %d\n", cd->del_count ); storeAppendPrintf(e, "\t bits: per entry: %d on: %d capacity: %d util: %d%%\n", cd->bits_per_entry, stats.bit_on_count, stats.bit_count, xpercentInt(stats.bit_on_count, stats.bit_count) ); storeAppendPrintf(e, "\t bit-seq: count: %d avg.len: %.2f\n", stats.bseq_count, xdiv(stats.bseq_len_sum, stats.bseq_count) ); }
static long divdiffgraph(Stats *s, Stats *t, void *va) { Arg *a; a = va; return xdiv(t->n[a->index] - s->n[a->index], t->n[a->index2] - s->n[a->index2]); }
static void httpHeaderFieldStatDumper(StoreEntry * sentry, int idx, double val, double size, int count) { const int id = (int) val; const int valid_id = id >= 0 && id < HDR_ENUM_END; const char *name = valid_id ? strBuf(Headers[id].name) : "INVALID"; int visible = count > 0; /* for entries with zero count, list only those that belong to current type of message */ if (!visible && valid_id && dump_stat->owner_mask) visible = CBIT_TEST(*dump_stat->owner_mask, id); if (visible) storeAppendPrintf(sentry, "%2d\t %-20s\t %5d\t %6.2f\n", id, name, count, xdiv(count, dump_stat->busyDestroyedCount)); }
int main (int na, char **av) { struct xpr s, t, f; char nbx[64], nby[64]; FILE *fp; if (na != 2) { printf ("para: input_file\n"); exit (-1); } fp = fopen (*++av, "r"); printf (" Test of Elementary Operations\n"); while (fscanf (fp, "%s %s", nbx, nby) != EOF) { s = atox (nbx); t = atox (nby); printf ("\n x= "); xprxpr (s, decd); printf ("\n y= "); xprxpr (t, decd); /* extended precision addition */ printf ("\nadd\n"); f = xadd (s, t, 0); printf (" %16.10f\n", xtodbl (f)); xprxpr (f, decd); /* extended precision subtraction */ printf ("\nsubtract\n"); f = xadd (s, t, 1); printf (" %16.10f\n", xtodbl (f)); xprxpr (f, decd); /* extended precision multiplication */ printf ("\nmultiply\n"); f = xmul (s, t); printf (" %16.10f\n", xtodbl (f)); xprxpr (f, decd); /* extended precision division */ printf ("\ndivide\n"); f = xdiv (s, t); printf (" %16.10f\n", xtodbl (f)); xprxpr (f, decd); } putchar ('\n'); return 0; }
static struct xpr c_tan (struct xpr z) { struct xpr s, f, d; int m; unsigned short k; if (x_exp (&z) < xK_lin) return z; s = xneg (xmul (z, z)); for (k = 1; k <= XDIM && s.nmm[k] == 0; k++); if ((xsigerr (s.nmm[0] == 0xffff && k > XDIM, XFPOFLOW, NULL))) return xZero; else { f = xZero; for (d = inttox (m = xMS_trg); m > 1;) { f = xdiv (s, xadd (d, f, 0)); d = inttox (m -= 2); } return xdiv (z, xadd (d, f, 0)); } }
struct xpr xsin (struct xpr z) { int k; z = rred (z, 's', &k); if (x_exp (&z) >= xK_lin) { z = c_tan (xpr2 (z, -1)); z = xdiv (xpr2 (z, 1), xadd (xOne, xmul (z, z), 0)); } if ((k)) return xneg (z); else return z; }
struct xpr xcos (struct xpr z) { int k; z = rred (z, 'c', &k); if (x_exp (&z) < xK_lin) { if ((k)) return xneg (xOne); else return xOne; } z = c_tan (xpr2 (z, -1)); z = xmul (z, z); z = xdiv (xadd (xOne, z, 1), xadd (xOne, z, 0)); if ((k)) return xneg (z); else return z; }
void OSystem_Android::updateScreen() { //ENTER(); GLTHREADCHECK; if (!JNI::haveSurface()) return; if (_game_pbuf) { int pitch = _game_texture->width() * _game_texture->getPixelFormat().bytesPerPixel; _game_texture->updateBuffer(0, 0, _game_texture->width(), _game_texture->height(), _game_pbuf.getRawBuffer(), pitch); } if (!_force_redraw && !_game_texture->dirty() && !_overlay_texture->dirty() && !_mouse_texture->dirty()) return; _force_redraw = false; if (_frame_buffer) { _frame_buffer->detach(); glViewport(0,0, _egl_surface_width, _egl_surface_height); } // clear pointer leftovers in dead areas clearScreen(kClear); // TODO this doesnt work on those sucky drivers, do it differently // if (_show_overlay) // GLCALL(glColor4ub(0x9f, 0x9f, 0x9f, 0x9f)); if (true || _focus_rect.isEmpty()) { _game_texture->drawTextureRect(); drawVirtControls(); } else { // TODO what is this and do we have engines using it? #if 0 GLCALL(glPushMatrix()); GLCALL(glScalex(xdiv(_egl_surface_width, _focus_rect.width()), xdiv(_egl_surface_height, _focus_rect.height()), 1 << 16)); GLCALL(glTranslatex(-_focus_rect.left << 16, -_focus_rect.top << 16, 0)); GLCALL(glScalex(xdiv(_game_texture->width(), _egl_surface_width), xdiv(_game_texture->height(), _egl_surface_height), 1 << 16)); _game_texture->drawTextureRect(); GLCALL(glPopMatrix()); #endif } int cs = _mouse_targetscale; if (_show_overlay) { // TODO see above // GLCALL(glColor4ub(0xff, 0xff, 0xff, 0xff)); // ugly, but the modern theme sets a wacko factor, only god knows why cs = 1; GLCALL(_overlay_texture->drawTextureRect()); } if (_show_mouse && !_mouse_texture->isEmpty()) { const Common::Point &mouse = getEventManager()->getMousePos(); if (_show_overlay) { _mouse_texture->drawTexture(mouse.x * cs, mouse.y * cs, _mouse_texture->width(), _mouse_texture->height()); } // TODO: Port the non-overlay code as well? #if 0 if (_show_overlay) { } else { const Common::Rect &r = _game_texture->getDrawRect(); GLCALL(glTranslatex(r.left << 16, r.top << 16, 0)); GLCALL(glScalex(xdiv(r.width(), _game_texture->width()), xdiv(r.height(), _game_texture->height()), 1 << 16)); } GLCALL(glTranslatex((-_mouse_hotspot.x * cs) << 16, (-_mouse_hotspot.y * cs) << 16, 0)); #endif } if (!JNI::swapBuffers()) LOGW("swapBuffers failed: 0x%x", glGetError()); if (_frame_buffer) _frame_buffer->attach(); }
void OSystem_Android::updateScreen() { //ENTER(); GLTHREADCHECK; if (!JNI::haveSurface()) return; if (!_force_redraw && !_game_texture->dirty() && !_overlay_texture->dirty() && !_mouse_texture->dirty()) return; _force_redraw = false; // clear pointer leftovers in dead areas // also, HTC's GLES drivers are made of fail and don't preserve the buffer // ( http://www.khronos.org/registry/egl/specs/EGLTechNote0001.html ) if ((_show_overlay || _htc_fail) && !_fullscreen) clearScreen(kClear); GLCALL(glPushMatrix()); if (_shake_offset != 0 || (!_focus_rect.isEmpty() && !Common::Rect(_game_texture->width(), _game_texture->height()).contains(_focus_rect))) { // These are the only cases where _game_texture doesn't // cover the entire screen. clearScreen(kClear); // Move everything up by _shake_offset (game) pixels GLCALL(glTranslatex(0, -_shake_offset << 16, 0)); } // TODO this doesn't work on those sucky drivers, do it differently // if (_show_overlay) // GLCALL(glColor4ub(0x9f, 0x9f, 0x9f, 0x9f)); if (_focus_rect.isEmpty()) { _game_texture->drawTextureRect(); } else { GLCALL(glPushMatrix()); GLCALL(glScalex(xdiv(_egl_surface_width, _focus_rect.width()), xdiv(_egl_surface_height, _focus_rect.height()), 1 << 16)); GLCALL(glTranslatex(-_focus_rect.left << 16, -_focus_rect.top << 16, 0)); GLCALL(glScalex(xdiv(_game_texture->width(), _egl_surface_width), xdiv(_game_texture->height(), _egl_surface_height), 1 << 16)); _game_texture->drawTextureRect(); GLCALL(glPopMatrix()); } int cs = _mouse_targetscale; if (_show_overlay) { // TODO see above // GLCALL(glColor4ub(0xff, 0xff, 0xff, 0xff)); // ugly, but the modern theme sets a wacko factor, only god knows why cs = 1; GLCALL(_overlay_texture->drawTextureRect()); } if (_show_mouse && !_mouse_texture->isEmpty()) { GLCALL(glPushMatrix()); const Common::Point &mouse = getEventManager()->getMousePos(); // Scale up ScummVM -> OpenGL (pixel) coordinates if (_show_overlay) { GLCALL(glScalex(xdiv(_egl_surface_width, _overlay_texture->width()), xdiv(_egl_surface_height, _overlay_texture->height()), 1 << 16)); } else { const Common::Rect &r = _game_texture->getDrawRect(); GLCALL(glTranslatex(r.left << 16, r.top << 16, 0)); GLCALL(glScalex(xdiv(r.width(), _game_texture->width()), xdiv(r.height(), _game_texture->height()), 1 << 16)); } GLCALL(glTranslatex((-_mouse_hotspot.x * cs) << 16, (-_mouse_hotspot.y * cs) << 16, 0)); // Note the extra half texel to position the mouse in // the middle of the x,y square: GLCALL(glTranslatex((mouse.x << 16) | 1 << 15, (mouse.y << 16) | 1 << 15, 0)); GLCALL(glScalex(cs << 16, cs << 16, 1 << 16)); _mouse_texture->drawTextureOrigin(); GLCALL(glPopMatrix()); } GLCALL(glPopMatrix()); if (!JNI::swapBuffers()) LOGW("swapBuffers failed: 0x%x", glGetError()); }
/* somewhat safer calculation of %s */ double xpercent(double part, double whole) { return xdiv(100 * part, whole); }