Debian Codegraph @

src/dumbswap.c

raw symbols SCIP
1 /* not clever, but comprehensible, I let the compiler do the optimization */
2
3 double dumb_dswap(double x,int swap_code){
4 if(!swap_code) return x;
5 union {
6 double d;
7 char bytes[8];
8 } from;
9 union {
10 double d;
11 char bytes[8];
12 } to;
13 from.d = x;
14 to.bytes[0] = from.bytes[7];
15 to.bytes[1] = from.bytes[6];
16 to.bytes[2] = from.bytes[5];
17 to.bytes[3] = from.bytes[4];
18 to.bytes[4] = from.bytes[3];
19 to.bytes[5] = from.bytes[2];
20 to.bytes[6] = from.bytes[1];
21 to.bytes[7] = from.bytes[0];
22 return to.d;
23 }
24
25 int dumb_iswap(int x,int swap_code){
26 if(!swap_code) return x;
27 union {
28 int i;
29 char bytes[4];
30 } from;
31 union {
32 int i;
33 char bytes[4];
34 } to;
35 from.i = x;
36 to.bytes[0] = from.bytes[3];
37 to.bytes[1] = from.bytes[2];
38 to.bytes[2] = from.bytes[1];
39 to.bytes[3] = from.bytes[0];
40 return to.i;
41 }
42
43 short dumb_sswap(short x, int swap_code){
44 if(!swap_code) return x;
45 union {
46 short s;
47 char bytes[2];
48 } from;
49 union {
50 short s;
51 char bytes[2];
52 } to;
53 from.s = x;
54 to.bytes[0] = from.bytes[1];
55 to.bytes[1] = from.bytes[0];
56 return to.s;
57 }
58
59 float dumb_fswap(float x, int swap_code){
60 if(!swap_code) return x;
61 union {
62 float f;
63 char bytes[4];
64 } from;
65 union {
66 float f;
67 char bytes[4];
68 } to;
69 from.f = x;
70 to.bytes[0] = from.bytes[3];
71 to.bytes[1] = from.bytes[2];
72 to.bytes[2] = from.bytes[1];
73 to.bytes[3] = from.bytes[0];
74 return to.f;
75 }