aarch64: Add assembly support for -fsanitize=hwaddress tagged globals.
[libav.git] / libavutil / tests / eval.c
1 /*
2 * This file is part of Libav.
3 *
4 * Libav is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * Libav is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with Libav; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <math.h>
20 #include <stdio.h>
21 #include <string.h>
22
23 #include "libavutil/libm.h"
24 #include "libavutil/timer.h"
25 #include "libavutil/eval.h"
26
27 static const double const_values[] = {
28 M_PI,
29 M_E,
30 0
31 };
32
33 static const char *const const_names[] = {
34 "PI",
35 "E",
36 0
37 };
38
39 int main(int argc, char **argv)
40 {
41 int i;
42 double d;
43 const char *const *expr;
44 static const char *const exprs[] = {
45 "",
46 "1;2",
47 "-20",
48 "-PI",
49 "+PI",
50 "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
51 "80G/80Gi",
52 "1k",
53 "1Gi",
54 "1gi",
55 "1GiFoo",
56 "1k+1k",
57 "1Gi*3foo",
58 "foo",
59 "foo(",
60 "foo()",
61 "foo)",
62 "sin",
63 "sin(",
64 "sin()",
65 "sin)",
66 "sin 10",
67 "sin(1,2,3)",
68 "sin(1 )",
69 "1",
70 "1foo",
71 "bar + PI + E + 100f*2 + foo",
72 "13k + 12f - foo(1, 2)",
73 "1gi",
74 "1Gi",
75 "st(0, 123)",
76 "st(1, 123); ld(1)",
77 "lte(0, 1)",
78 "lte(1, 1)",
79 "lte(1, 0)",
80 "lt(0, 1)",
81 "lt(1, 1)",
82 "gt(1, 0)",
83 "gt(2, 7)",
84 "gte(122, 122)",
85 /* compute 1+2+...+N */
86 "st(0, 1); while(lte(ld(0), 100), st(1, ld(1)+ld(0));st(0, ld(0)+1)); ld(1)",
87 /* compute Fib(N) */
88 "st(1, 1); st(2, 2); st(0, 1); while(lte(ld(0),10), st(3, ld(1)+ld(2)); st(1, ld(2)); st(2, ld(3)); st(0, ld(0)+1)); ld(3)",
89 "while(0, 10)",
90 "st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0)); st(0, ld(0)+1))",
91 "isnan(1)",
92 "isnan(NAN)",
93 "isnan(INF)",
94 "isinf(1)",
95 "isinf(NAN)",
96 "isinf(INF)",
97 "floor(NAN)",
98 "floor(123.123)",
99 "floor(-123.123)",
100 "trunc(123.123)",
101 "trunc(-123.123)",
102 "ceil(123.123)",
103 "ceil(-123.123)",
104 "sqrt(1764)",
105 "isnan(sqrt(-1))",
106 "not(1)",
107 "not(NAN)",
108 "not(0)",
109 "6.0206dB",
110 "-3.0103dB",
111 NULL
112 };
113
114 for (expr = exprs; *expr; expr++) {
115 printf("Evaluating '%s'\n", *expr);
116 av_expr_parse_and_eval(&d, *expr,
117 const_names, const_values,
118 NULL, NULL, NULL, NULL, NULL, 0, NULL);
119 if (isnan(d))
120 printf("'%s' -> nan\n\n", *expr);
121 else
122 printf("'%s' -> %f\n\n", *expr, d);
123 }
124
125 av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
126 const_names, const_values,
127 NULL, NULL, NULL, NULL, NULL, 0, NULL);
128 printf("%f == 12.7\n", d);
129 av_expr_parse_and_eval(&d, "80G/80Gi",
130 const_names, const_values,
131 NULL, NULL, NULL, NULL, NULL, 0, NULL);
132 printf("%f == 0.931322575\n", d);
133
134 if (argc > 1 && !strcmp(argv[1], "-t")) {
135 for (i = 0; i < 1050; i++) {
136 START_TIMER;
137 av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
138 const_names, const_values,
139 NULL, NULL, NULL, NULL, NULL, 0, NULL);
140 STOP_TIMER("av_expr_parse_and_eval");
141 }
142 }
143
144 return 0;
145 }