-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex.go
More file actions
50 lines (41 loc) · 1.29 KB
/
complex.go
File metadata and controls
50 lines (41 loc) · 1.29 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
package lexy
// Codecs for complex64 and complex128 types.
//
// The encoded order is real part first, imaginary part second.
type (
complex64Codec struct{}
complex128Codec struct{}
)
func (complex64Codec) Append(buf []byte, value complex64) []byte {
buf = stdFloat32.Append(buf, real(value))
return stdFloat32.Append(buf, imag(value))
}
func (complex64Codec) Put(buf []byte, value complex64) []byte {
buf = stdFloat32.Put(buf, real(value))
return stdFloat32.Put(buf, imag(value))
}
func (complex64Codec) Get(buf []byte) (complex64, []byte) {
realPart, buf := stdFloat32.Get(buf)
imagPart, buf := stdFloat32.Get(buf)
return complex(realPart, imagPart), buf
}
func (complex64Codec) RequiresTerminator() bool {
return false
}
func (complex128Codec) Append(buf []byte, value complex128) []byte {
//nolint:mnd
buf = stdFloat64.Append(extend(buf, 16), real(value))
return stdFloat64.Append(buf, imag(value))
}
func (complex128Codec) Put(buf []byte, value complex128) []byte {
buf = stdFloat64.Put(buf, real(value))
return stdFloat64.Put(buf, imag(value))
}
func (complex128Codec) Get(buf []byte) (complex128, []byte) {
realPart, buf := stdFloat64.Get(buf)
imagPart, buf := stdFloat64.Get(buf)
return complex(realPart, imagPart), buf
}
func (complex128Codec) RequiresTerminator() bool {
return false
}