source: CIVL/examples/experimental/floatsum2.cvl

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.7 KB
Line 
1#include <civlc.cvh>
2
3#define N 4
4$input float x[N];
5$input float epsilon;
6
7typedef struct Interval {
8 float left;
9 float right;
10} Interval;
11
12Interval emptyInterval;
13
14Interval makeInterval(float left, float right) {
15 Interval result;
16
17 if (left <= right) {
18 result.left = left;
19 result.right = right;
20 } else {
21 result.left = 0;
22 result.right = -1;
23 }
24 return result;
25}
26
27int empty(Interval a) {
28 return a.left > a.right;
29}
30
31int subset(Interval a, Interval b) {
32 return a.left >= b.left && a.right <= b.right;
33}
34
35Interval round(Interval a) {
36 int empty_a = empty(a);
37
38 if (empty_a)
39 return a;
40 else {
41 float left, right;
42 Interval result;
43
44 if (a.left>=0) {
45 left = (1-epsilon)*a.left;
46 right = (1+epsilon)*a.right;
47 } else {
48 left = (1+epsilon)*a.left;
49 if (a.right>=0)
50 right = (1+epsilon)*a.right;
51 else
52 right = (1-epsilon)*a.right;
53 }
54 result = makeInterval(left, right);
55 return result;
56 }
57}
58
59Interval plus(Interval a, Interval b) {
60 int empty_a = empty(a);
61
62 if (empty_a)
63 return a;
64 else {
65 int empty_b = empty(b);
66
67 if (empty_b)
68 return b;
69 else {
70 Interval result;
71
72 result = makeInterval(a.left + b.left, a.right + b.right);
73 return result;
74 }
75 }
76}
77
78Interval fplus(Interval a, Interval b) {
79 Interval result;
80
81 result = round(plus(a,b));
82 return result;
83}
84
85void main() {
86 Interval a[N];
87 Interval r1, r2;
88 int test;
89
90 emptyInterval = makeInterval(0,-1);
91 $assume(epsilon>0 && epsilon<0.1);
92 for (int i=0; i<N; i++) {
93 a[i].left = x[i];
94 a[i].right = x[i];
95 }
96 r1 = fplus(fplus(fplus(a[0],a[1]),a[2]),a[3]);
97 r2 = fplus(fplus(a[0],a[1]), fplus(a[2],a[3]));
98 test = subset(r2, r1);
99 $assert(test);
100}
Note: See TracBrowser for help on using the repository browser.