-
Notifications
You must be signed in to change notification settings - Fork 0
/
norm.erb.js
54 lines (35 loc) · 1.08 KB
/
norm.erb.js
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
CSMath.norm2 = function() {
var list = Array.prototype.slice.call(arguments).sort(function (a, b) { return Math.abs(b) - Math.abs(a) })
var head = CSMath.abs(list[0]), s = 1.0, c = 0.0, n = list.length
for (var i = 1; i < n; i++) {
var value = CSMath.abs(list[i]) / head
value = value * value
var y = c + value
var u = value - (y - c)
var t = s + y
var v = y - (t - s)
var z = u + v
s = t + z
c = z - (s - t)
}
return CSMath.sqrt(s * head)
}
CSMath.hypot2 = function() {
var list = Array.prototype.slice.call(arguments).sort(function (a, b) { return Math.abs(b) - Math.abs(a) })
var head = CSMath.abs(list[0]), s = 1.0, c = 0.0, n = list.length
for (var i = 1; i < n; i++) {
var value = CSMath.abs(list[i]) / head
value = value * value
var y = c + value
var u = value - (y - c)
var t = s + y
var v = y - (t - s)
var z = u + v
s = t + z
c = z - (s - t)
}
return s * head
}
CSMath.min = Math.min
CSMath.max = Math.max
CSMath.hypot = CSMath.norm2