int main (int argc, char *argv[]) { mpfr_t x, y, z, s; tests_start_mpfr (); mpfr_init (x); mpfr_init (s); mpfr_init (y); mpfr_init (z); /* check special cases */ mpfr_set_prec (x, 2); mpfr_set_prec (y, 2); mpfr_set_prec (z, 2); mpfr_set_prec (s, 2); mpfr_set_str (x, "-0.75", 10, GMP_RNDN); mpfr_set_str (y, "0.5", 10, GMP_RNDN); mpfr_set_str (z, "0.375", 10, GMP_RNDN); mpfr_fma (s, x, y, z, GMP_RNDU); /* result is 0 */ if (mpfr_cmp_ui(s, 0)) { printf("Error: -0.75 * 0.5 + 0.375 should be equal to 0 for prec=2\n"); exit(1); } mpfr_set_prec (x, 27); mpfr_set_prec (y, 27); mpfr_set_prec (z, 27); mpfr_set_prec (s, 27); mpfr_set_str_binary (x, "1.11111111111111111111111111e-1"); mpfr_set (y, x, GMP_RNDN); mpfr_set_str_binary (z, "-1.00011110100011001011001001e-1"); if (mpfr_fma (s, x, y, z, GMP_RNDN) >= 0) { printf ("Wrong inexact flag for x=y=1-2^(-27)\n"); exit (1); } mpfr_set_nan (x); mpfr_random (y); mpfr_random (z); mpfr_fma (s, x, y, z, GMP_RNDN); if (!mpfr_nan_p (s)) { printf ("evaluation of function in x=NAN does not return NAN"); exit (1); } mpfr_set_nan (y); mpfr_random (x); mpfr_random (z); mpfr_fma (s, x, y, z, GMP_RNDN); if (!mpfr_nan_p(s)) { printf ("evaluation of function in y=NAN does not return NAN"); exit (1); } mpfr_set_nan (z); mpfr_random (y); mpfr_random (x); mpfr_fma (s, x, y, z, GMP_RNDN); if (!mpfr_nan_p (s)) { printf ("evaluation of function in z=NAN does not return NAN"); exit (1); } mpfr_set_inf (x, 1); mpfr_set_inf (y, 1); mpfr_set_inf (z, 1); mpfr_fma (s, x, y, z, GMP_RNDN); if (!mpfr_inf_p (s) || mpfr_sgn (s) < 0) { printf ("Error for (+inf) * (+inf) + (+inf)\n"); exit (1); } mpfr_set_inf (x, -1); mpfr_set_inf (y, -1); mpfr_set_inf (z, 1); mpfr_fma (s, x, y, z, GMP_RNDN); if (!mpfr_inf_p (s) || mpfr_sgn (s) < 0) { printf ("Error for (-inf) * (-inf) + (+inf)\n"); exit (1); } mpfr_set_inf (x, 1); mpfr_set_inf (y, -1); mpfr_set_inf (z, -1); mpfr_fma (s, x, y, z, GMP_RNDN); if (!mpfr_inf_p (s) || mpfr_sgn (s) > 0) { printf ("Error for (+inf) * (-inf) + (-inf)\n"); exit (1); } mpfr_set_inf (x, -1); mpfr_set_inf (y, 1); mpfr_set_inf (z, -1); mpfr_fma (s, x, y, z, GMP_RNDN); if (!mpfr_inf_p (s) || mpfr_sgn (s) > 0) { printf ("Error for (-inf) * (+inf) + (-inf)\n"); exit (1); } mpfr_set_inf (x, 1); mpfr_set_ui (y, 0, GMP_RNDN); mpfr_random (z); mpfr_fma (s, x, y, z, GMP_RNDN); if (!mpfr_nan_p (s)) { printf ("evaluation of function in x=INF y=0 does not return NAN"); exit (1); } mpfr_set_inf (y, 1); mpfr_set_ui (x, 0, GMP_RNDN); mpfr_random (z); mpfr_fma (s, x, y, z, GMP_RNDN); if (!mpfr_nan_p (s)) { printf ("evaluation of function in x=0 y=INF does not return NAN"); exit (1); } mpfr_set_inf (x, 1); mpfr_random (y); /* always positive */ mpfr_set_inf (z, -1); mpfr_fma (s, x, y, z, GMP_RNDN); if (!mpfr_nan_p (s)) { printf ("evaluation of function in x=INF y>0 z=-INF does not return NAN"); exit (1); } mpfr_set_inf (y, 1); mpfr_random (x); mpfr_set_inf (z, -1); mpfr_fma (s, x, y, z, GMP_RNDN); if (!mpfr_nan_p (s)) { printf ("evaluation of function in x>0 y=INF z=-INF does not return NAN"); exit (1); } mpfr_set_inf (x, 1); mpfr_random (y); mpfr_random (z); mpfr_fma (s, x, y, z, GMP_RNDN); if (!mpfr_inf_p (s) || mpfr_sgn (s) < 0) { printf ("evaluation of function in x=INF does not return INF"); exit (1); } mpfr_set_inf (y, 1); mpfr_random (x); mpfr_random (z); mpfr_fma (s, x, y, z, GMP_RNDN); if (!mpfr_inf_p (s) || mpfr_sgn (s) < 0) { printf ("evaluation of function in y=INF does not return INF"); exit (1); } mpfr_set_inf (z, 1); mpfr_random (x); mpfr_random (y); mpfr_fma (s, x, y, z, GMP_RNDN); if (!mpfr_inf_p (s) || mpfr_sgn (s) < 0) { printf ("evaluation of function in z=INF does not return INF"); exit (1); } mpfr_set_ui (x, 0, GMP_RNDN); mpfr_random (y); mpfr_random (z); mpfr_fma (s, x, y, z, GMP_RNDN); if (mpfr_cmp (s, z)) { printf ("evaluation of function in x=0 does not return z\n"); exit (1); } mpfr_set_ui (y, 0, GMP_RNDN); mpfr_random (x); mpfr_random (z); mpfr_fma (s, x, y, z, GMP_RNDN); if (mpfr_cmp (s, z)) { printf ("evaluation of function in y=0 does not return z\n"); exit (1); } { mp_prec_t prec; mpfr_t t, slong; mp_rnd_t rnd; int inexact, compare; unsigned int n; mp_prec_t p0=2, p1=200; unsigned int N=200; mpfr_init (t); mpfr_init (slong); /* generic test */ for (prec = p0; prec <= p1; prec++) { mpfr_set_prec (x, prec); mpfr_set_prec (y, prec); mpfr_set_prec (z, prec); mpfr_set_prec (s, prec); mpfr_set_prec (t, prec); for (n=0; n<N; n++) { mpfr_random (x); mpfr_random (y); mpfr_random (z); if (randlimb () % 2) mpfr_neg (x, x, GMP_RNDN); if (randlimb () % 2) mpfr_neg (y, y, GMP_RNDN); if (randlimb () % 2) mpfr_neg (z, z, GMP_RNDN); rnd = (mp_rnd_t) RND_RAND (); mpfr_set_prec (slong, 2 * prec); if (mpfr_mul (slong, x, y, rnd)) { printf ("x*y should be exact\n"); exit (1); } compare = mpfr_add (t, slong, z, rnd); inexact = mpfr_fma (s, x, y, z, rnd); if (mpfr_cmp (s, t)) { printf ("results differ for x="); mpfr_out_str (stdout, 2, prec, x, GMP_RNDN); printf (" y="); mpfr_out_str (stdout, 2, prec, y, GMP_RNDN); printf (" z="); mpfr_out_str (stdout, 2, prec, z, GMP_RNDN); printf (" prec=%u rnd_mode=%s\n", (unsigned int) prec, mpfr_print_rnd_mode (rnd)); printf ("got "); mpfr_out_str (stdout, 2, prec, s, GMP_RNDN); puts (""); printf ("expected "); mpfr_out_str (stdout, 2, prec, t, GMP_RNDN); puts (""); printf ("approx "); mpfr_print_binary (slong); puts (""); exit (1); } if (((inexact == 0) && (compare != 0)) || ((inexact < 0) && (compare >= 0)) || ((inexact > 0) && (compare <= 0))) { printf ("Wrong inexact flag for rnd=%s: expected %d, got %d\n", mpfr_print_rnd_mode (rnd), compare, inexact); printf (" x="); mpfr_out_str (stdout, 2, 0, x, GMP_RNDN); printf (" y="); mpfr_out_str (stdout, 2, 0, y, GMP_RNDN); printf (" z="); mpfr_out_str (stdout, 2, 0, z, GMP_RNDN); printf (" s="); mpfr_out_str (stdout, 2, 0, s, GMP_RNDN); printf ("\n"); exit (1); } } } mpfr_clear (t); mpfr_clear (slong); } mpfr_clear (x); mpfr_clear (y); mpfr_clear (z); mpfr_clear (s); test_exact (); test_overflow1 (); test_overflow2 (); test_underflow1 (); test_underflow2 (); tests_end_mpfr (); return 0; }
enum piglit_result piglit_display(void) { bool warn = false, pass = true; GLuint rb, fbo; int i, j; float times[ARRAY_LENGTH(gl_formats)][ARRAY_LENGTH(gl_types)]; glGenRenderbuffersEXT(1, &rb); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA, texture_size, texture_size); pass &= piglit_check_gl_error(GL_NO_ERROR); glGenFramebuffersEXT(1, &fbo); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, rb); pass &= piglit_check_gl_error(GL_NO_ERROR); /* Set up basic GL stuff */ glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); warn = !test_exact(); for (i = 0; i < ARRAY_LENGTH(gl_formats); ++i) { for (j = 0; j < ARRAY_LENGTH(gl_types); ++j) { if (!valid_combination(gl_formats[i], gl_types[j])) continue; pass &= run_test(gl_formats[i], gl_types[j], ×[i][j]); } } glDisable(GL_TEXTURE_2D); glDeleteFramebuffers(1, &fbo); glDeleteRenderbuffers(1, &rb); if (benchmark) { fprintf(stdout, "internalFormat, format, type, time (us/call)\n"); for (i = 0; i < ARRAY_LENGTH(gl_formats); ++i) { for (j = 0; j < ARRAY_LENGTH(gl_types); ++j) { if (!valid_combination(gl_formats[i], gl_types[j])) continue; fprintf(stdout, "%s, %s, %s, %.3f\n", piglit_get_gl_enum_name(format->internal_format), piglit_get_gl_enum_name(gl_formats[i]), piglit_get_gl_enum_name(gl_types[j]), times[i][j]); } } } if (pass) { return warn ? PIGLIT_WARN : PIGLIT_PASS; } else { return PIGLIT_FAIL; } }