-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdim256.go
More file actions
84 lines (79 loc) · 1.62 KB
/
Copy pathdim256.go
File metadata and controls
84 lines (79 loc) · 1.62 KB
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
package floats
// Dim returns the maximum of a-b or 0.
//
// Special cases are:
//
// +Inf.Dim(+Inf) = NaN
// -Inf.Dim(-Inf) = NaN
// x.Dim(NaN) = NaN.Dim(x) = NaN
func (a Float256) Dim(b Float256) Float256 {
// The special cases result in NaN after the subtraction:
// +Inf - +Inf = NaN
// -Inf - -Inf = NaN
// NaN - b = NaN
// a - NaN = NaN
v := a.Sub(b)
if v.Le(Float256{}) {
// v is negative or 0
return Float256{}
}
// v is positive or NaN
return v
}
// Max returns the larger of a or b.
//
// Special cases are:
//
// x.Max(+Inf) = +Inf.Max(x) = +Inf
// x.Max(NaN) = NaN.Max(x) = NaN
// +0.Max(±0) = ±0.Max(+0) = +0
// -0.Max(-0) = -0
//
// Note that this differs from the built-in function max when called
// with NaN and +Inf.
func (a Float256) Max(b Float256) Float256 {
// special cases
switch {
case a.IsInf(1) || b.IsInf(1):
return NewFloat256Inf(1)
case a.IsNaN() || b.IsNaN():
return NewFloat256NaN()
case a.IsZero() && a.Eq(b):
if a.Signbit() {
return b
}
return a
}
if a.Gt(b) {
return a
}
return b
}
// Min returns the smaller of a or b.
//
// Special cases are:
//
// x.Min(-Inf) = -Inf.Min(x) = -Inf
// x.Min(NaN) = NaN.Min(x) = NaN
// -0.Min(±0) = ±0.Min(-0) = -0
//
// Note that this differs from the built-in function min when called
// with NaN and -Inf.
func (a Float256) Min(b Float256) Float256 {
// special cases
switch {
case a.IsInf(-1) || b.IsInf(-1):
return NewFloat256Inf(-1)
case a.IsNaN() || b.IsNaN():
return NewFloat256NaN()
case a.IsZero() && a.Eq(b):
if a.Signbit() {
return a
}
return b
}
if a.Lt(b) {
return a
}
return b
}