void process_hodge_key(int keyword) { int sidflag = 0, nosflag = 0; switch (keyword) { case 'i': if (increment >= 16) increment -= 8; else if (increment) increment--; sidflag = 1; break; case 'I': if (increment >= 8) { if (increment < 255-8) increment += 8; else increment = 255; } else increment++; sidflag = 1; break; case 'n': if (maxstate >= 24) maxstate -= 8; else if (maxstate > 1) maxstate--; nosflag = 1; break; case 'N': if (maxstate >= 16) { if (maxstate < 255-8) maxstate += 8; else maxstate = 255; } else maxstate++; nosflag = 1; break; } if (sidflag || nosflag) newcaflag = rebuildflag = 1; if (sidflag) TWICE(setIncrementDecrement(1)); if (nosflag) TWICE(setNumberOfStates(1)); }
int main (int argc, char *argv[]) { printf ("4*TWICE(3) is %d\n", 4*TWICE(3)); printf ("4*twice(3) is %d\n", 4*twice(3)); return 0; } // main
int process_hodge(int i) { int row = i/3; int col = i%3; if (row==0) { switch(col) { case 0: { double d = maxstate; if (GetNumber(&tweakNT[row].TB,&d,GS_INTEGER,1,255)) maxstate = d; TWICE(setNumberOfStates(1)); TWICE(key_push(current_main_item,true)); newcaflag = rebuildflag = 1; return 0; } case 1: return 'n'; case 2: return 'N'; } } switch(col) { case 0: { double d = increment; if (GetNumber(&tweakNT[row].TB,&d,GS_INTEGER,0,255)) increment = d; TWICE(setIncrementDecrement(1)); TWICE(key_push(current_main_item,true)); newcaflag = rebuildflag = 1; return 0; } case 1: return 'i'; case 2: return 'I'; } return 0; }
int main (int argc, char *argv[]) { long x; // For doing pointless computations int i; // Counter variable for loops struct timeval start; // The start of a computation struct timeval finish; // The end of a computation long elapsed; // Elapsed time in microseconds // Compute how long a lot of calls to TWICE take x = 0; gettimeofday(&start, NULL); for (i = 0; i < REPETITIONS; i++) { x += TWICE(3); } gettimeofday(&finish, NULL); elapsed = 1000000 * (finish.tv_sec - start.tv_sec) + (finish.tv_usec - start.tv_usec); printf ("Using the macro, we spent %ld microseconds.\n", elapsed); printf ("Our result is %ld.\n\n", x); // Compute how long a lot of calls to TWICE take x = 0; gettimeofday(&start, NULL); for (i = 0; i < REPETITIONS; i++) { x += twice(3); } gettimeofday(&finish, NULL); elapsed = 1000000 * (finish.tv_sec - start.tv_sec) + (finish.tv_usec - start.tv_usec); printf ("Using the procedure, we spent %ld microseconds.\n", elapsed); printf ("Our result is %ld.\n\n", x); return 0; } // main
void run_tests(void) { volatile long double vld; long double ld; volatile double vd; double d; volatile float vf; float f; int x; test("sign bits", fpequal(-0.0, -0.0) && !fpequal(0.0, -0.0)); vd = NAN; test("NaN equality", fpequal(NAN, NAN) && NAN != NAN && vd != vd); feclearexcept(ALL_STD_EXCEPT); test("NaN comparison returns false", !(vd <= vd)); /* * XXX disabled; gcc/amd64 botches this IEEE 754 requirement by * emitting ucomisd instead of comisd. */ skiptest("FENV_ACCESS: NaN comparison raises invalid exception", fetestexcept(ALL_STD_EXCEPT) == FE_INVALID); vd = 0.0; run_zero_opt_test(vd, vd); vd = INFINITY; run_inf_opt_test(vd); feclearexcept(ALL_STD_EXCEPT); vd = INFINITY; x = (int)vd; /* XXX disabled (works with -O0); gcc doesn't support FENV_ACCESS */ skiptest("FENV_ACCESS: Inf->int conversion raises invalid exception", fetestexcept(ALL_STD_EXCEPT) == FE_INVALID); /* Raising an inexact exception here is an IEEE-854 requirement. */ feclearexcept(ALL_STD_EXCEPT); vd = 0.75; x = (int)vd; test("0.75->int conversion rounds toward 0, raises inexact exception", x == 0 && fetestexcept(ALL_STD_EXCEPT) == FE_INEXACT); feclearexcept(ALL_STD_EXCEPT); vd = -42.0; x = (int)vd; test("-42.0->int conversion is exact, raises no exception", x == -42 && fetestexcept(ALL_STD_EXCEPT) == 0); feclearexcept(ALL_STD_EXCEPT); x = (int)INFINITY; /* XXX disabled; gcc doesn't support FENV_ACCESS */ skiptest("FENV_ACCESS: const Inf->int conversion raises invalid", fetestexcept(ALL_STD_EXCEPT) == FE_INVALID); feclearexcept(ALL_STD_EXCEPT); x = (int)0.5; /* XXX disabled; gcc doesn't support FENV_ACCESS */ skiptest("FENV_ACCESS: const double->int conversion raises inexact", x == 0 && fetestexcept(ALL_STD_EXCEPT) == FE_INEXACT); test("compile-time constants don't have too much precision", one_f == 1.0L && one_d == 1.0L && one_ld == 1.0L); test("const minimum rounding precision", 1.0F + FLT_EPSILON != 1.0F && 1.0 + DBL_EPSILON != 1.0 && 1.0L + LDBL_EPSILON != 1.0L); /* It isn't the compiler's fault if this fails on FreeBSD/i386. */ vf = FLT_EPSILON; vd = DBL_EPSILON; vld = LDBL_EPSILON; test("runtime minimum rounding precision", 1.0F + vf != 1.0F && 1.0 + vd != 1.0 && 1.0L + vld != 1.0L); test("explicit float to float conversion discards extra precision", (float)(1.0F + FLT_EPSILON * 0.5F) == 1.0F && (float)(1.0F + vf * 0.5F) == 1.0F); test("explicit double to float conversion discards extra precision", (float)(1.0 + FLT_EPSILON * 0.5) == 1.0F && (float)(1.0 + vf * 0.5) == 1.0F); test("explicit ldouble to float conversion discards extra precision", (float)(1.0L + FLT_EPSILON * 0.5L) == 1.0F && (float)(1.0L + vf * 0.5L) == 1.0F); test("explicit double to double conversion discards extra precision", (double)(1.0 + DBL_EPSILON * 0.5) == 1.0 && (double)(1.0 + vd * 0.5) == 1.0); test("explicit ldouble to double conversion discards extra precision", (double)(1.0L + DBL_EPSILON * 0.5L) == 1.0 && (double)(1.0L + vd * 0.5L) == 1.0); /* * FLT_EVAL_METHOD > 1 implies that float expressions are always * evaluated in double precision or higher, but some compilers get * this wrong when registers spill to memory. The following expression * forces a spill when there are at most 8 FP registers. */ test("implicit promption to double or higher precision is consistent", #if FLT_EVAL_METHOD == 1 || FLT_EVAL_METHOD == 2 || defined(__i386__) TWICE(TWICE(TWICE(TWICE(TWICE( TWICE(TWICE(TWICE(TWICE(1.0F + vf * 0.5F))))))))) == (1.0 + FLT_EPSILON * 0.5) * 512.0 #else 1 #endif ); f = 1.0 + FLT_EPSILON * 0.5; d = 1.0L + DBL_EPSILON * 0.5L; test("const assignment discards extra precision", f == 1.0F && d == 1.0); f = 1.0 + vf * 0.5; d = 1.0L + vd * 0.5L; test("variable assignment discards explicit extra precision", f == 1.0F && d == 1.0); f = 1.0F + vf * 0.5F; d = 1.0 + vd * 0.5; test("variable assignment discards implicit extra precision", f == 1.0F && d == 1.0); test("return discards extra precision", tofloat(1.0 + vf * 0.5) == 1.0F && todouble(1.0L + vd * 0.5L) == 1.0); fesetround(FE_UPWARD); /* XXX disabled (works with -frounding-math) */ skiptest("FENV_ACCESS: constant arithmetic respects rounding mode", 1.0F + FLT_MIN == 1.0F + FLT_EPSILON && 1.0 + DBL_MIN == 1.0 + DBL_EPSILON && 1.0L + LDBL_MIN == 1.0L + LDBL_EPSILON); fesetround(FE_TONEAREST); ld = vld * 0.5; test("associativity is respected", 1.0L + ld + (LDBL_EPSILON * 0.5) == 1.0L && 1.0L + (LDBL_EPSILON * 0.5) + ld == 1.0L && ld + 1.0 + (LDBL_EPSILON * 0.5) == 1.0L && ld + (LDBL_EPSILON * 0.5) + 1.0 == 1.0L + LDBL_EPSILON); }
int main(int argc, char **argv) { unsigned short grafboard; extern int disk_error_handler(int errval, int ax, int bp, int si); char *p; allocatebuffers(); if (init_mem_err) { cprintf("\r\n\r\nSorry, not enough memory to run Toy Universes.\r\n"); return -1; } harderr(disk_error_handler); /* Find out if we have a VGA or EGA at all. */ grafboard = QueryGrafix(); if ((grafboard & 0x200) != 0x200) { printf("This programs requires EGA capability.\n"); exit(-1); } if (grafboard == 0xffff || InitGrafix(-EGA640x350) < 0) { printf("Metagraphics not installed. Execute the command:\n"); printf("metashel /i\n"); printf("and then try again.\n"); exit(-1); } vgaflag = -1; while (argc > 1) { if (argv[1][0] == '-') { switch (argv[1][1]) { case 'e': vgaflag = 0; break; case 'v': vgaflag = 1; break; } } argc--; argv++; } if (vgaflag == -1) { if ((grafboard & 0x300) == 0x300) vgaflag = 1; else vgaflag = 0; } Comm = QueryComm(); if (Comm == MsDriver) InitMouse(MsDriver); else if (Comm == MsCOM1) InitMouse(MsCOM1); else if (Comm == MsCOM2) InitMouse(MsCOM2); else if (Comm & 3) InitMouse(COM1); /* * Probably wrong. Need to check for MS mouse address in some special * way. */ randomize(); p = searchpath("system16.fnt"); if (p) LoadFont(p); installmode(); load_preset_palettes(); usepalette(); current_main_item = 0; usepalette(); TWICE(initialize_buttons()); ShowCursor(); if (allocatefailflag) ErrorBox("Not enough memory for hi-res."); /* Lets see if there is enough for a later gif */ if (!memok(20712L)) /* Added up mallocs in comprs.c */ ErrorBox("There may not be enough memory to save or view a Gif."); prog_init = 1; if (!setjmp(beatit)) { while (!exitflag) { rebuildflag = 0; if (newcaflag && !donescreenflag) { loadlookuptable(increment, maxstate); newcaflag = 0; } if (newcaoflag) { unsigned char *p1,*p2; static int firsttime = true; switch(caotype) { case CA_HODGE: p1 = (char *)HODGE_colortable; p2 = HODGE_ct; break; case CA_EAT: p1 = (char *)EAT_colortable; p2 = EAT_ct; break; case CA_TUBE: p1 = (char *)TUBE_colortable; p2 = TUBE_ct; break; case CA_NLUKY: p1 = (char *)NLUKY_colortable; p2 = NLUKY_ct; break; } memcpy(vgacolortable,p1,16*3); if (!hasVGA) memcpy(egacolortable,p2,16); if (!firsttime) { TWICE(initialize_numbers()); } else firsttime = false; usepalette(); newcaoflag = 0; current_main_item = -1; } if (blankflag) { blankbuffers(); blankflag = 0; } if (randomizeflag) { carandomize(); randomizeflag = 0; } while (!exitflag && !rebuildflag) { if (onestep || !stopped) { if (display_mode == HI) hiresupdate(); else loresupdate(); if (onestep) onestep--; } if (spinflag && (!stopped || (iteration++ > spinspeed))) { if (spinflag == 1) spinpalette(); else revspinpalette(); iteration = 0; } checkkeyboard(); if (newcaflag) rebuildflag = 1; } } } StopMouse(); StopEvent(); grayflag = 0; grayscale(); SetDisplay(TextPg0); return exitflag; }
int main(int argc, char *argv[]) { int terse_mode = 0; int print_header = 0; int word_size = 8*sizeof(long); char *dialect = langs[LANG]; int64_t tmin_dec_val = (int64_t) TMIN_DEC; int64_t tmin_hex_val = (int64_t) TMIN_HEX; char * CZd = COMP_ZERO(TMIN_DEC); char * CZh = COMP_ZERO(TMIN_HEX); char * czd = comp_zero(TMIN_DEC); char * czh = comp_zero(TMIN_HEX); int64_t TWICEd = TWICE(TMIN_DEC); int64_t TWICEh = TWICE(TMIN_HEX); int c; while ((c = getopt(argc, argv, "th")) != -1) { switch (c) { case 't': terse_mode = 1; break; case 'h': print_header = 1; break; default: break; } } if (terse_mode) { if (print_header) { printf("word size:dialect:decimal:hex:CZ decimal: CZ hex:cz decimal:cz hex:2x decimal:2x hex\n"); } printf("%d:%s:%lld:%lld:%s:%s:%s:%s:%lld:%lld\n", word_size, dialect, tmin_dec_val, tmin_hex_val, CZd, CZh, czd, czh, TWICEd, TWICEh); } else { printf("Long word size = %d\n", (int) (8*sizeof(long))); printf("Dialect = %s\n", langs[LANG]); printf(" COMP_ZERO\n"); printf("\t%s\t(0x%" PRIx64 ") %s 0\n", STMIN_DEC, (int64_t) TMIN_DEC, COMP_ZERO(TMIN_DEC)); printf("\t%s\t(0x%" PRIx64 ") %s 0\n", STMIN_HEX, (int64_t) TMIN_HEX, COMP_ZERO(TMIN_HEX)); printf(" COMP_TMIN\n"); printf("\t%s\t(0x%" PRIx64 ") %s %s\n", STMIN_DEC, (int64_t) TMIN_DEC, COMP_TMIN(TMIN_DEC), STMIN_DEC); printf("\t%s\t(0x%" PRIx64 ") %s %s\n", STMIN_HEX, (int64_t) TMIN_HEX, COMP_TMIN(TMIN_HEX), STMIN_DEC); printf(" comp_zero\n"); printf("\t%s\t(0x%" PRIx64 ") %s 0\n", STMIN_DEC, (int64_t) TMIN_DEC, comp_zero(TMIN_DEC)); printf("\t%s\t(0x%" PRIx64 ") %s 0\n", STMIN_HEX, (int64_t) TMIN_HEX, comp_zero(TMIN_HEX)); printf(" comp_tmin\n"); printf("\t%s\t(0x%" PRIx64 ") %s %s\n", STMIN_DEC, (int64_t) TMIN_DEC, comp_tmin(TMIN_DEC), STMIN_DEC); printf("\t%s\t(0x%" PRIx64 ") %s %s\n", STMIN_HEX, (int64_t) TMIN_HEX, comp_tmin(TMIN_HEX), STMIN_DEC); printf(" TWICE\n"); printf("\t2*%s\t(2*0x%" PRIx64 ") = %lld (0x%" PRIx64 ")\n", STMIN_DEC, (int64_t) TMIN_DEC, (int64_t) TWICE(TMIN_DEC), (int64_t) TWICE(TMIN_DEC)); printf("\t2*%s\t(2*0x%" PRIx64 ") = %lld (0x%" PRIx64 ")\n", STMIN_HEX, (int64_t) TMIN_HEX, (int64_t) TWICE(TMIN_HEX), (int64_t) TWICE(TMIN_HEX)); printf("\n"); } return 0; }