blob: 49088ab0207e0bc681bd777bbaa00d7bae059fee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
#include <math.h>
#include "common.h"
#ifdef FUNCTION_PROFILE
#include "functable.h"
#endif
#ifndef CBLAS
void NAME(FLOAT *DA, FLOAT *DB, FLOAT *C, FLOAT *S){
#else
void CNAME(FLOAT *DA, FLOAT *DB, FLOAT *C, FLOAT *S){
#endif
#if defined(__i386__) || defined(__x86_64__) || defined(__ia64__)
long double da = *DA;
long double db = *DB;
long double c;
long double s;
long double r, roe, z;
long double ada = fabs(da);
long double adb = fabs(db);
long double scale = ada + adb;
#ifndef CBLAS
PRINT_DEBUG_NAME;
#else
PRINT_DEBUG_CNAME;
#endif
roe = db;
if (ada > adb) roe = da;
if (scale == ZERO) {
*C = ONE;
*S = ZERO;
*DA = ZERO;
*DB = ZERO;
} else {
r = sqrt(da * da + db * db);
if (roe < 0) r = -r;
c = da / r;
s = db / r;
z = ONE;
if (da != ZERO) {
if (ada > adb){
z = s;
} else {
z = ONE / c;
}
}
*C = c;
*S = s;
*DA = r;
*DB = z;
}
#else
FLOAT da = *DA;
FLOAT db = *DB;
FLOAT c = *C;
FLOAT s = *S;
FLOAT r, roe, z;
FLOAT ada = fabs(da);
FLOAT adb = fabs(db);
FLOAT scale = ada + adb;
#ifndef CBLAS
PRINT_DEBUG_NAME;
#else
PRINT_DEBUG_CNAME;
#endif
roe = db;
if (ada > adb) roe = da;
if (scale == ZERO) {
*C = ONE;
*S = ZERO;
*DA = ZERO;
*DB = ZERO;
} else {
FLOAT aa = da / scale;
FLOAT bb = db / scale;
r = scale * sqrt(aa * aa + bb * bb);
if (roe < 0) r = -r;
c = da / r;
s = db / r;
z = ONE;
if (ada > adb) z = s;
if ((ada < adb) && (c != ZERO)) z = ONE / c;
*C = c;
*S = s;
*DA = r;
*DB = z;
}
#endif
return;
}
|