source: CIVL/examples/possibleBug/classCastException.cvl@ 67bc1cf

1.23 2.0 main test-branch
Last change on this file since 67bc1cf was 4a76a55, checked in by Yihao Yan <yihaoyan1@…>, 9 years ago

possible bug

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

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[4a76a55]1#include <stdio.h>
2#include <math.h>
3#ifdef _CIVL
4$input double Jb;
5$input double alphad[10];
6#endif
7void func(double* alpha, int n, double* J) {
8 for(int i=0;i<n;i++) {
9 *J += sin(alpha[i]);
10 }
11}
12void func_d(double *alpha, double *alphad, int n, double *J, double *Jd) {
13 for (int i = 0; i < n; ++i) {
14 *Jd = *Jd + alphad[i]*cos(alpha[i]);
15 *J += sin(alpha[i]);
16 }
17}
18void func_b(double *alpha, double *alphab, int n, double *J, double *Jb) {
19 for (int i = n-1; i > -1; --i) {
20 alphab[i] = alphab[i] + cos(alpha[i])*(*Jb);
21 }
22}
23
24
25int main(int argc, char** argv) {
26 // dot product test: alphad*alphab == Jd*Jb
27 const int n = 10;
28 double alpha[n], alphad[n], alphab[n];
29 double J, Jd, Jb;
30
31
32 for(int i=0; i<n; i++) {
33 alpha[i] = 1.5*i;
34 alphab[i] = 0.0;
35 }
36 J = 0.0;
37 Jd = 0.0;
38
39
40 #ifndef _CIVL
41 Jb = 1.0;
42 for(int i=0; i<n; i++) {
43 alphad[i] = 0.0;
44 }
45 alphad[3] += 1;
46 #endif
47
48
49 func(&alpha[0],n,&J);
50 func_d(&alpha[0],&alphad[0],n,&J,&Jd);
51 func_b(&alpha[0],&alphab[0],n,&J,&Jb);
52
53
54 double dp = 0.0;
55 for(int i=0;i<n;i++) {
56 dp += alphad[i]*alphab[i];
57 }
58
59
60 printf("%f %f\n",dp, Jd*Jb);
61}
Note: See TracBrowser for help on using the repository browser.