1 // PR target/39002
2 // { dg-do run }
3
4 struct S
5 {
6 double x;
7 double y;
8 double z;
9 };
10
11 double foo (S *, S *);
12 void bar (S *, S *, S *, double &, double &, double &);
13
14 double
foo(S * a1,S * a2)15 foo (S *a1, S *a2)
16 {
17 return __builtin_sqrt ((a1->x - a2->x) * (a1->x - a2->x)
18 + (a1->y - a2->y) * (a1->y - a2->y)
19 + (a1->z - a2->z) * (a1->z - a2->z));
20 }
21
22 void
bar(S * p,S * q,S * r,double & x,double & y,double & z)23 bar (S *p, S *q, S *r, double &x, double &y, double &z)
24 {
25 if (foo (p, q) == 0.0)
26 {
27 x = r->x;
28 y = r->y;
29 z = r->z;
30 return;
31 }
32 if (foo (p, r) == 0.0)
33 {
34 x = r->x;
35 y = r->y;
36 z = r->z;
37 return;
38 }
39 if (foo (q, r) == 0.0)
40 {
41 x = r->x;
42 y = r->y;
43 z = r->z;
44 return;
45 }
46
47 double a1, b1, c1, d1, e1;
48 double dx, dy, dz, dw, dv;
49
50 a1 = q->x - p->x;
51 b1 = q->y - p->y;
52 c1 = q->z - p->z;
53 e1 = __builtin_sqrt (a1 * a1 + b1 * b1 + c1 * c1);
54 a1 = a1 / e1;
55 b1 = b1 / e1;
56 c1 = c1 / e1;
57 dx = p->x - r->x;
58 dy = p->y - r->y;
59 dz = p->z - r->z;
60 dw = dx * dx + dy * dy + dz * dz;
61 dv = 2.0 * dx * a1 + 2.0 * dy * b1 + 2.0 * dz * c1;
62 d1 = -dv / 2.0;
63 x = p->x + (a1 * d1);
64 y = p->y + (b1 * d1);
65 z = p->z + (c1 * d1);
66 return;
67 }
68
69 int
main(void)70 main (void)
71 {
72 S a, b, c, d, *p, *q, *r;
73
74 p = &a;
75 q = &b;
76 r = &c;
77 a.x = 0.0;
78 a.y = 0.0;
79 a.z = 0.0;
80 b.x = 1.0;
81 b.y = 0.0;
82 b.z = 0.0;
83 c.x = 0.0;
84 c.y = 1.0;
85 c.z = 0.0;
86 bar (p, q, r, d.x, d.y, d.z);
87 return 0;
88 }
89