root / pobysoC-4.0 / src / test-pobyso-dirty-find-zeros.c
Historique | Voir | Annoter | Télécharger (5,53 ko)
1 | 141 | storres | /** @file test-pobyso-dirty-find-zeros.c
|
---|---|---|---|
2 | 141 | storres | * Name & purpose
|
3 | 141 | storres | *
|
4 | 141 | storres | * Three arguments are expected : an functional expression, a lowerBound
|
5 | 141 | storres | * and an upper bound. The zeroes of the functional expression are
|
6 | 141 | storres | * searched for over the [lower bound, upper bound] interval.
|
7 | 141 | storres | * If only the functional expression is literally "NULL" the
|
8 | 141 | storres | * pobyso_dirty_find_zeros is tested with a NULL argument as for the function.
|
9 | 141 | storres | *
|
10 | 141 | storres | * The others arguments are not looked for.
|
11 | 141 | storres | *
|
12 | 141 | storres | * @author S. T.
|
13 | 141 | storres | * @date 2014-12-05
|
14 | 141 | storres | *
|
15 | 141 | storres | * @details Verbosity manipulation are performed to make sur that verbosity
|
16 | 141 | storres | * suppression is correctly managed in pobyso_is_constant_expression()
|
17 | 141 | storres | * function.
|
18 | 141 | storres | */
|
19 | 141 | storres | /******************************************************************************/
|
20 | 141 | storres | /* Headers, applying the "particular to general" convention.*/
|
21 | 141 | storres | |
22 | 141 | storres | #include "pobyso.h" |
23 | 141 | storres | |
24 | 141 | storres | /* includes of local headers */
|
25 | 141 | storres | |
26 | 141 | storres | /* includes of project headers */
|
27 | 141 | storres | |
28 | 141 | storres | /* includes of system headers */
|
29 | 141 | storres | #include <stdlib.h> |
30 | 141 | storres | /* Other declarations */
|
31 | 141 | storres | |
32 | 141 | storres | /* Internal prototypes */
|
33 | 141 | storres | |
34 | 141 | storres | /* Types, constants and macros definitions */
|
35 | 141 | storres | |
36 | 141 | storres | /* Global variables */
|
37 | 141 | storres | |
38 | 141 | storres | /* Functions */
|
39 | 141 | storres | |
40 | 141 | storres | int
|
41 | 141 | storres | main(int argc, char** argv) |
42 | 141 | storres | { |
43 | 141 | storres | pobyso_func_exp_t funcExpSo = NULL;
|
44 | 141 | storres | sollya_obj_t lowerBoundSo = NULL;
|
45 | 141 | storres | sollya_obj_t upperBoundSo = NULL;
|
46 | 141 | storres | mpfr_t lowerBoundMp; |
47 | 141 | storres | mpfr_t upperBoundMp; |
48 | 141 | storres | int zerosCount = 0; |
49 | 141 | storres | mpfr_t* zerosArrayMp = NULL;
|
50 | 141 | storres | int i;
|
51 | 141 | storres | |
52 | 141 | storres | sollya_lib_init(); |
53 | 141 | storres | |
54 | 141 | storres | /* Two command line arguments expected. */
|
55 | 141 | storres | if (argc < 4) |
56 | 141 | storres | { |
57 | 141 | storres | fprintf(stderr,"\n\n");
|
58 | 141 | storres | fprintf(stderr, "Usage: %s funcExp lowerBound upperBound\n", argv[0]); |
59 | 141 | storres | fprintf(stderr, |
60 | 141 | storres | " funcExp: a quoted functional expression for Sollya;\n");
|
61 | 141 | storres | fprintf(stderr, |
62 | 141 | storres | " lowerBound: a (possibly quoted) Sollya constant expression for the lower bound;\n");
|
63 | 141 | storres | fprintf(stderr, |
64 | 141 | storres | " upperBound: a (possibly quoted) Sollya constant expression for the upper bound.");
|
65 | 141 | storres | fprintf(stderr,"\n\n");
|
66 | 141 | storres | sollya_lib_close(); |
67 | 141 | storres | return 1; |
68 | 141 | storres | } |
69 | 141 | storres | |
70 | 141 | storres | if (! strcmp(argv[1], "NULL")) /* First parameter is the "NULL" string) */ |
71 | 141 | storres | { |
72 | 141 | storres | zerosArrayMp = pobyso_dirty_find_zeros_bounds(NULL,
|
73 | 141 | storres | lowerBoundMp, |
74 | 141 | storres | upperBoundMp, |
75 | 141 | storres | &zerosCount); |
76 | 141 | storres | sollya_lib_close(); |
77 | 141 | storres | /* No clean up needed. */
|
78 | 141 | storres | return 1; |
79 | 141 | storres | } |
80 | 141 | storres | pobyso_set_canonical_on(); |
81 | 141 | storres | lowerBoundSo = pobyso_parse_string(argv[2]);
|
82 | 141 | storres | if (lowerBoundSo == NULL) |
83 | 141 | storres | { |
84 | 141 | storres | fprintf(stderr, |
85 | 141 | storres | "\n\n%s: can't parse \"%s\" to a valid expression. Aborting!\n\n",
|
86 | 141 | storres | argv[0], argv[2]); |
87 | 141 | storres | sollya_lib_close(); |
88 | 141 | storres | return 1; |
89 | 141 | storres | } |
90 | 141 | storres | upperBoundSo = pobyso_parse_string(argv[3]);
|
91 | 141 | storres | if (upperBoundSo == NULL) |
92 | 141 | storres | { |
93 | 141 | storres | fprintf(stderr, |
94 | 141 | storres | "\n\n%s: can't parse \"%s\" to a valid expression. Aborting!\n\n",
|
95 | 141 | storres | argv[0], argv[3]); |
96 | 141 | storres | sollya_lib_clear_obj(lowerBoundSo); |
97 | 141 | storres | sollya_lib_close(); |
98 | 141 | storres | return 1; |
99 | 141 | storres | } |
100 | 141 | storres | if (! pobyso_is_constant_expression(lowerBoundSo) ||
|
101 | 141 | storres | ! pobyso_is_constant_expression(upperBoundSo)) |
102 | 141 | storres | { |
103 | 141 | storres | fprintf(stderr, |
104 | 141 | storres | "\n\n%s: can't evaluate \"%s\" nor \"%s\" to a constant expression. Aborting!\n\n",
|
105 | 141 | storres | argv[0], argv[2], argv[3]); |
106 | 141 | storres | sollya_lib_clear_obj(lowerBoundSo); |
107 | 141 | storres | sollya_lib_clear_obj(upperBoundSo); |
108 | 141 | storres | sollya_lib_close(); |
109 | 141 | storres | return 1; |
110 | 141 | storres | } |
111 | 141 | storres | mpfr_init2(lowerBoundMp, 512);
|
112 | 141 | storres | if (! sollya_lib_get_constant(lowerBoundMp, lowerBoundSo))
|
113 | 141 | storres | { |
114 | 141 | storres | fprintf(stderr, |
115 | 141 | storres | "\n\n%s: can't recover the value of \"%s\". Aborting!\n\n",
|
116 | 141 | storres | argv[0], argv[2]); |
117 | 141 | storres | mpfr_clear(lowerBoundMp); |
118 | 141 | storres | sollya_lib_clear_obj(lowerBoundSo); |
119 | 141 | storres | sollya_lib_clear_obj(upperBoundSo); |
120 | 141 | storres | sollya_lib_close(); |
121 | 141 | storres | return 1; |
122 | 141 | storres | } |
123 | 141 | storres | mpfr_init2(upperBoundMp, 512);
|
124 | 141 | storres | if (! sollya_lib_get_constant(upperBoundMp, upperBoundSo))
|
125 | 141 | storres | { |
126 | 141 | storres | fprintf(stderr, |
127 | 141 | storres | "\n\n%s: can't recover the value of \"%s\". Aborting!\n\n",
|
128 | 141 | storres | argv[0], argv[3]); |
129 | 141 | storres | mpfr_clear(lowerBoundMp); |
130 | 141 | storres | mpfr_clear(upperBoundMp); |
131 | 141 | storres | sollya_lib_clear_obj(lowerBoundSo); |
132 | 141 | storres | sollya_lib_clear_obj(upperBoundSo); |
133 | 141 | storres | sollya_lib_close(); |
134 | 141 | storres | return 1; |
135 | 141 | storres | } |
136 | 141 | storres | if (argc > 4) |
137 | 141 | storres | { |
138 | 141 | storres | fprintf(stdout, "Bounds: [");
|
139 | 141 | storres | mpfr_out_str(stdout, 10, 0, lowerBoundMp, MPFR_RNDN); |
140 | 141 | storres | fprintf(stdout, ", ");
|
141 | 141 | storres | mpfr_out_str(stdout, 10, 0, upperBoundMp, MPFR_RNDN); |
142 | 141 | storres | fprintf(stdout, "]\n");
|
143 | 141 | storres | } |
144 | 141 | storres | /* Not needed any more. */
|
145 | 141 | storres | sollya_lib_clear_obj(lowerBoundSo); |
146 | 141 | storres | sollya_lib_clear_obj(upperBoundSo); |
147 | 141 | storres | funcExpSo = pobyso_parse_string(argv[1]);
|
148 | 141 | storres | if (funcExpSo == NULL) |
149 | 141 | storres | { |
150 | 141 | storres | fprintf(stderr, |
151 | 141 | storres | "\n\n%s: could not parse \"%s\" as a valid Sollya expression. Aborting!\n\n",
|
152 | 141 | storres | argv[0], argv[1]); |
153 | 141 | storres | mpfr_clear(lowerBoundMp); |
154 | 141 | storres | mpfr_clear(upperBoundMp); |
155 | 141 | storres | sollya_lib_close(); |
156 | 141 | storres | return 1; |
157 | 141 | storres | } |
158 | 141 | storres | if (argc > 4) |
159 | 141 | storres | { |
160 | 141 | storres | fprintf(stdout, "Functional expression: ");
|
161 | 141 | storres | pobyso_autoprint(funcExpSo); |
162 | 141 | storres | } |
163 | 141 | storres | zerosArrayMp = pobyso_dirty_find_zeros_bounds(funcExpSo, |
164 | 141 | storres | lowerBoundMp, |
165 | 141 | storres | upperBoundMp, |
166 | 141 | storres | &zerosCount); |
167 | 141 | storres | sollya_lib_clear_obj(funcExpSo); |
168 | 141 | storres | mpfr_clear(lowerBoundMp); |
169 | 141 | storres | mpfr_clear(upperBoundMp); |
170 | 141 | storres | if (zerosCount < 0) |
171 | 141 | storres | { |
172 | 141 | storres | return 1; |
173 | 141 | storres | } |
174 | 141 | storres | if (zerosCount == 0) |
175 | 141 | storres | { |
176 | 141 | storres | return 0; |
177 | 141 | storres | } |
178 | 141 | storres | if (zerosCount > 0) |
179 | 141 | storres | { |
180 | 141 | storres | fprintf(stdout, "Zeroes: ");
|
181 | 141 | storres | for (i = 0 ; i < zerosCount ; i++) |
182 | 141 | storres | { |
183 | 141 | storres | mpfr_out_str(stdout, 10, 0, zerosArrayMp[i], MPFR_RNDN); |
184 | 141 | storres | mpfr_clear(zerosArrayMp[i]); |
185 | 141 | storres | if (i < zerosCount-1) fprintf(stdout, ", "); |
186 | 141 | storres | } |
187 | 141 | storres | fprintf(stdout, ".\n");
|
188 | 141 | storres | } |
189 | 141 | storres | else
|
190 | 141 | storres | { |
191 | 141 | storres | fprintf(stdout, "No zeroes!\n");
|
192 | 141 | storres | } |
193 | 141 | storres | if (zerosCount > 0) free(zerosArrayMp); |
194 | 141 | storres | sollya_lib_close(); |
195 | 141 | storres | return 0; |
196 | 141 | storres | } /* End main */ |