Annotation of OpenXM_contrib/gmp/mpfr/tests/tmul_ui.c, Revision 1.1.1.1
1.1 maekawa 1: /* Test file for mpfr_mul_ui.
2:
3: Copyright (C) 1999 PolKA project, Inria Lorraine and Loria
4:
5: This file is part of the MPFR Library.
6:
7: The MPFR Library is free software; you can redistribute it and/or modify
8: it under the terms of the GNU Library General Public License as published by
9: the Free Software Foundation; either version 2 of the License, or (at your
10: option) any later version.
11:
12: The MPFR Library is distributed in the hope that it will be useful, but
13: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15: License for more details.
16:
17: You should have received a copy of the GNU Library General Public License
18: along with the MPFR Library; see the file COPYING.LIB. If not, write to
19: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20: MA 02111-1307, USA. */
21:
22: #include <stdio.h>
23: #include <stdlib.h>
24: #include "gmp.h"
25: #include "gmp-impl.h"
26: #include "mpfr.h"
27: #include "time.h"
28:
29: int
30: main(int argc, char **argv)
31: {
32: mpfr_t x, y;
33:
34: mpfr_init2(x, 53); mpfr_init2(y, 53);
35:
36: /* checks that result is normalized */
37: mpfr_set_d(y, 6.93147180559945286227e-01, GMP_RNDZ);
38: mpfr_mul_ui(x, y, 1, GMP_RNDZ);
39: if (MANT(x)[PREC(x)/BITS_PER_MP_LIMB] >> (BITS_PER_MP_LIMB-1) == 0) {
40: fprintf(stderr, "Error in mpfr_mul_ui: result not normalized\n");
41: exit(1);
42: }
43: if (mpfr_cmp(x,y)) {
44: fprintf(stderr, "Error in mpfr_mul_ui: 1*y != y\n");
45: printf("y= "); mpfr_print_raw(y); putchar('\n');
46: printf("1*y="); mpfr_print_raw(x); putchar('\n');
47: exit(1);
48: }
49:
50: mpfr_set_d(x, 1.0/3.0, GMP_RNDZ);
51: mpfr_mul_ui(x, x, 3, GMP_RNDU);
52: if (mpfr_get_d(x) != 1.0) {
53: fprintf(stderr, "Error in mpfr_mul_ui: U(Z(1/3)*3) does not give 1\n"); exit(1);
54: }
55:
56: /* checks sign is correct */
57: mpfr_set_d(x, -2.0, GMP_RNDZ);
58: mpfr_set_d(y, 3.0, GMP_RNDZ);
59: mpfr_mul_ui(x, y, 4, GMP_RNDZ);
60: if (SIGN(x) != 1) {
61: fprintf(stderr, "Error in mpfr_mul_ui: 4*3.0 does not give a positive result\n"); exit(1);
62: }
63:
64: mpfr_clear(x); mpfr_clear(y);
65: exit (0);
66: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>