Révision 133
pobysoC-4.0/src/pobyso.h (revision 133) | ||
---|---|---|
68 | 68 |
void |
69 | 69 |
pobyso_autoprint_v(sollya_obj_t soObj, va_list va); |
70 | 70 |
|
71 |
/** |
|
72 |
* Check if a sollya object is a constant expression. |
|
73 |
* @return 1 if true and zero otherwise |
|
74 |
*/ |
|
75 |
int |
|
76 |
pobyso_is_constant_expression(sollya_obj_t obj_to_text); |
|
71 | 77 |
|
72 |
|
|
73 | 78 |
/** |
74 |
* Parse a string to create a Sollya object. |
|
75 |
* A very thin wrapper around the sollya_lib_parse_string() function. |
|
76 |
* If the final ";" is forgotten in the expression, it is added by the |
|
77 |
* function. |
|
78 |
* @return a Sollya expression if successes, a Sollya error if fails. |
|
79 |
* Create a Sollya monomial from a Sollya constant, |
|
80 |
* the coefficient, and an integer, the exponent |
|
81 |
* @return a Sollya functional expression if successes, or a Sollya error |
|
82 |
* if fails. |
|
79 | 83 |
*/ |
80 |
pobyso_error_t
|
|
81 |
pobyso_parse(const char* expression);
|
|
84 |
sollya_obj_t
|
|
85 |
pobyso_new_monomial(pobyso_func_exp_t coefficient, long degree);
|
|
82 | 86 |
|
83 | 87 |
/** |
84 | 88 |
* A wrapper around the Sollya Remez function. |
... | ... | |
88 | 92 |
* A very thin wrapper around the sollya_lib_parse_string() function. |
89 | 93 |
* If the final ";" is forgotten in the expression, it is added by the |
90 | 94 |
* function. |
91 |
* @return a Sollya functional expression if successes, a Sollya error if fails. |
|
95 |
* @return a Sollya functional expression if successes, or a Sollya error |
|
96 |
* if fails. |
|
92 | 97 |
*/ |
93 | 98 |
pobyso_error_t |
94 | 99 |
pobyso_parse_string(const char* expression); |
pobysoC-4.0/src/test-pobyso-02.c (revision 133) | ||
---|---|---|
29 | 29 |
int |
30 | 30 |
main(int argc, char** argv) |
31 | 31 |
{ |
32 |
pobyso_func_exp_t f; |
|
32 |
pobyso_func_exp_t f = NULL; |
|
33 |
pobyso_func_exp_t one = NULL; |
|
33 | 34 |
sollya_lib_init(); |
34 | 35 |
pobyso_set_canonical_on(); |
35 | 36 |
f = pobyso_parse_string(argv[1]); |
... | ... | |
46 | 47 |
argv[1]); |
47 | 48 |
} |
48 | 49 |
sollya_lib_clear_obj(f); |
50 |
/* */ |
|
51 |
one = pobyso_parse_string("1"); |
|
52 |
if (pobyso_is_function(one)) |
|
53 |
{ |
|
54 |
pobyso_is_constant_expression(one); |
|
55 |
fprintf(stdout, "%s is a function.\n", "1"); |
|
56 |
} |
|
57 |
else |
|
58 |
{ |
|
59 |
fprintf(stdout,"%s is not a function.\n", "1"); |
|
60 |
} |
|
61 |
sollya_lib_clear_obj(one); |
|
62 |
|
|
49 | 63 |
sollya_lib_close(); |
50 | 64 |
return 0; |
51 | 65 |
} /* End main */ |
pobysoC-4.0/src/pobyso.c (revision 133) | ||
---|---|---|
42 | 42 |
va_end(va); |
43 | 43 |
} /* End pobyso_autoprint. */ |
44 | 44 |
|
45 |
/* @see pobyso.h#pobyso_is_constant_expression*/ |
|
46 |
int |
|
47 |
pobyso_is_constant_expression(sollya_obj_t obj_to_test) |
|
48 |
{ |
|
49 |
mpfr_t dummy; |
|
50 |
int test; |
|
51 |
sollya_obj_t verbosity_level = NULL; |
|
52 |
/* Test argument. */ |
|
53 |
if (obj_to_test == NULL) |
|
54 |
{ |
|
55 |
pobyso_error_message("pobyso_parse_string", |
|
56 |
"NULL_POINTER_ARGUMENT", |
|
57 |
"The expression is a NULL pointer"); |
|
58 |
return 0; |
|
59 |
} |
|
60 |
verbosity_level = pobyso_set_verbosity_off(); |
|
45 | 61 |
|
62 |
if (! sollya_lib_obj_is_function(obj_to_test)) |
|
63 |
{ |
|
64 |
pobyso_set_verbosity_to(verbosity_level); |
|
65 |
sollya_lib_clear_obj(verbosity_level); |
|
66 |
return 0; |
|
67 |
} |
|
68 |
mpfr_init2(dummy,64); |
|
69 |
/* Call to previous Sollya function resets verbosity. */ |
|
70 |
verbosity_level = pobyso_set_verbosity_off(); |
|
71 |
test = sollya_lib_get_constant(dummy, obj_to_test); |
|
72 |
mpfr_clear(dummy); |
|
73 |
pobyso_set_verbosity_to(verbosity_level); |
|
74 |
sollya_lib_clear_obj(verbosity_level); |
|
75 |
return test; |
|
76 |
} /* End pobyso_is_constant_expression. */ |
|
77 |
|
|
78 |
/** @see pobyso.h#pobyso_new_monomial. */ |
|
79 |
pobyso_func_exp_t |
|
80 |
pobyso_new_monomial(pobyso_func_exp_t coefficientSa, long degree) |
|
81 |
{ |
|
82 |
sollya_obj_t degreeSa = NULL; |
|
83 |
sollya_obj_t varToPowSa = NULL; |
|
84 |
sollya_obj_t monomialSa = NULL; |
|
85 |
if (coefficientSa == NULL) |
|
86 |
{ |
|
87 |
pobyso_error_message("pobyso_parse_string", |
|
88 |
"NULL_POINTER_ARGUMENT", |
|
89 |
"The expression is a NULL pointer"); |
|
90 |
return sollya_lib_error(); |
|
91 |
} |
|
92 |
if (! pobyso_is_constant_expression(coefficientSa)) |
|
93 |
{ |
|
94 |
return sollya_lib_error(); |
|
95 |
} |
|
96 |
if (degree < 0) |
|
97 |
{ |
|
98 |
return sollya_lib_error(); |
|
99 |
} |
|
100 |
degreeSa = sollya_lib_constant_from_int64(degree); |
|
101 |
varToPowSa = sollya_lib_build_function_pow(sollya_lib_free_variable(), |
|
102 |
degreeSa); |
|
103 |
monomialSa = sollya_lib_mul(coefficientSa,varToPowSa); |
|
104 |
sollya_lib_clear_obj(varToPowSa); |
|
105 |
return monomialSa; |
|
106 |
} /* End pobyso_new_monomial. */ |
|
107 |
|
|
46 | 108 |
/* @see pobyso.h#pobyso_parse_string*/ |
47 | 109 |
pobyso_func_exp_t |
48 | 110 |
pobyso_parse_string(const char* expression) |
pobysoC-4.0/src/Makefile (revision 133) | ||
---|---|---|
12 | 12 |
TEST_SOURCES = $(TEST_DIR)/$(TEST_DRIVER).c \ |
13 | 13 |
# Add the suites definition sources |
14 | 14 |
|
15 |
ALL_TARGETS = test-pobyso-01 test-pobyso-02 |
|
15 |
ALL_TARGETS = test-pobyso-01 test-pobyso-02 \ |
|
16 |
test-pobyso-constant-expression |
|
16 | 17 |
|
17 | 18 |
SCRATCH_PRG := $(patsubst %.c,%,$(wildcard *.c)) |
18 | 19 |
SCRATCH_ALL := $(SCRATCH_PRG) |
pobysoC-4.0/src/test-pobyso-constant-expression.c (revision 133) | ||
---|---|---|
1 |
/** @file test-pobyso-constant-expression.c |
|
2 |
* Name & purpose |
|
3 |
* |
|
4 |
* @author |
|
5 |
* @date |
|
6 |
* |
|
7 |
* @details Verbosity manipulation are performed to make sur that verbosity |
|
8 |
* suppression is correctly managed in pobyso_is_constant_expression() |
|
9 |
* function. |
|
10 |
*/ |
|
11 |
/******************************************************************************/ |
|
12 |
/* Headers, applying the "particular to general" convention.*/ |
|
13 |
|
|
14 |
#include "pobyso.h" |
|
15 |
|
|
16 |
/* includes of local headers */ |
|
17 |
|
|
18 |
/* includes of project headers */ |
|
19 |
|
|
20 |
/* includes of system headers */ |
|
21 |
|
|
22 |
/* Other declarations */ |
|
23 |
|
|
24 |
/* Internal prototypes */ |
|
25 |
|
|
26 |
/* Types, constants and macros definitions */ |
|
27 |
|
|
28 |
/* Global variables */ |
|
29 |
|
|
30 |
/* Functions */ |
|
31 |
|
|
32 |
int |
|
33 |
main(int argc, char** argv) |
|
34 |
{ |
|
35 |
pobyso_func_exp_t func_exp = NULL; |
|
36 |
sollya_obj_t verbosity = NULL; |
|
37 |
sollya_obj_t on = NULL; |
|
38 |
sollya_obj_t off = NULL; |
|
39 |
|
|
40 |
sollya_lib_init(); |
|
41 |
|
|
42 |
pobyso_set_canonical_on(); |
|
43 |
off = sollya_lib_off(); |
|
44 |
on = sollya_lib_on(); |
|
45 |
|
|
46 |
fprintf(stdout, "NULL argument:\n"); |
|
47 |
if (! pobyso_is_constant_expression(func_exp)) |
|
48 |
{ |
|
49 |
fprintf(stdout, "OK.\n"); |
|
50 |
} |
|
51 |
else |
|
52 |
{ |
|
53 |
fprintf(stdout, "Error for NULL argument.\n"); |
|
54 |
return 1; |
|
55 |
} |
|
56 |
|
|
57 |
fprintf(stdout, "Argument : 1\n"); |
|
58 |
func_exp = pobyso_parse_string("1"); |
|
59 |
if (pobyso_is_constant_expression(func_exp)) |
|
60 |
{ |
|
61 |
pobyso_autoprint(func_exp); |
|
62 |
fprintf(stdout, "OK.\n"); |
|
63 |
sollya_lib_clear_obj(func_exp); |
|
64 |
} |
|
65 |
else |
|
66 |
{ |
|
67 |
fprintf(stdout, "Error for \"1\".\n"); |
|
68 |
return 1; |
|
69 |
} |
|
70 |
verbosity = pobyso_set_verbosity_off(); |
|
71 |
func_exp = pobyso_parse_string("1.1"); |
|
72 |
pobyso_set_verbosity_to(verbosity); |
|
73 |
if (pobyso_is_constant_expression(func_exp)) |
|
74 |
{ |
|
75 |
pobyso_autoprint(func_exp); |
|
76 |
fprintf(stdout, "OK.\n"); |
|
77 |
sollya_lib_clear_obj(func_exp); |
|
78 |
} |
|
79 |
else |
|
80 |
{ |
|
81 |
fprintf(stdout, "Error for \"1.1\".\n"); |
|
82 |
return 1; |
|
83 |
} |
|
84 |
|
|
85 |
func_exp = pobyso_parse_string("1/2"); |
|
86 |
if (pobyso_is_constant_expression(func_exp)) |
|
87 |
{ |
|
88 |
pobyso_autoprint(func_exp); |
|
89 |
fprintf(stdout, "OK for \"1/2\".\n"); |
|
90 |
sollya_lib_clear_obj(func_exp); |
|
91 |
} |
|
92 |
else |
|
93 |
{ |
|
94 |
fprintf(stdout, "Error for \"1/2\".\n"); |
|
95 |
return 1; |
|
96 |
} |
|
97 |
|
|
98 |
verbosity = pobyso_set_verbosity_off(); |
|
99 |
sollya_lib_set_roundingwarnings(off); |
|
100 |
func_exp = sollya_lib_pi(); |
|
101 |
pobyso_set_verbosity_to(verbosity); |
|
102 |
sollya_lib_set_roundingwarnings(on); |
|
103 |
if (pobyso_is_constant_expression(func_exp)) |
|
104 |
{ |
|
105 |
pobyso_autoprint(func_exp); |
|
106 |
fprintf(stdout,"OK for pi.\n"); |
|
107 |
sollya_lib_clear_obj(func_exp); |
|
108 |
} |
|
109 |
else |
|
110 |
{ |
|
111 |
fprintf(stdout, "Error for \"pi\".\n"); |
|
112 |
return 1; |
|
113 |
} |
|
114 |
|
|
115 |
func_exp = pobyso_parse_string("x^2"); |
|
116 |
if (! pobyso_is_constant_expression(func_exp)) |
|
117 |
{ |
|
118 |
fprintf(stdout, "Non constant expression \"x^2\": OK\n"); |
|
119 |
} |
|
120 |
else |
|
121 |
{ |
|
122 |
fprintf(stdout, "Error for \"x^2\".\n"); |
|
123 |
return 1; |
|
124 |
} |
|
125 |
|
|
126 |
func_exp = pobyso_parse_string("cos(x)"); |
|
127 |
if (! pobyso_is_constant_expression(func_exp)) |
|
128 |
{ |
|
129 |
pobyso_autoprint(func_exp); |
|
130 |
fprintf(stdout, "Non constant expression \"cos(x)\": OK\n"); |
|
131 |
sollya_lib_clear_obj(func_exp); |
|
132 |
} |
|
133 |
else |
|
134 |
{ |
|
135 |
fprintf(stdout, "Error for \"cos(x)\".\n"); |
|
136 |
return 1; |
|
137 |
} |
|
138 |
|
|
139 |
verbosity = pobyso_set_verbosity_off(); |
|
140 |
func_exp = pobyso_parse_string("cos(pi)"); |
|
141 |
pobyso_set_verbosity_to(verbosity); |
|
142 |
{ |
|
143 |
pobyso_autoprint(func_exp); |
|
144 |
fprintf(stdout, "OK for \"cos(pi)\".\n"); |
|
145 |
sollya_lib_clear_obj(func_exp); |
|
146 |
} |
|
147 |
/* */ |
|
148 |
|
|
149 |
sollya_lib_close(); |
|
150 |
return 0; |
|
151 |
} /* End main */ |
|
0 | 152 |
Formats disponibles : Unified diff