Skip to content

Commit 800bb6f

Browse files
authored
1 parent 4c50fd8 commit 800bb6f

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

types.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ const (
198198
_CD = 1 << 4 // checking disabled
199199
)
200200

201-
// Various constants used in the LOC RR. See RFC 1887.
201+
// Various constants used in the LOC RR. See RFC 1876.
202202
const (
203203
LOC_EQUATOR = 1 << 31 // RFC 1876, Section 2.
204204
LOC_PRIMEMERIDIAN = 1 << 31 // RFC 1876, Section 2.
@@ -792,7 +792,10 @@ type LOC struct {
792792

793793
// cmToM takes a cm value expressed in RFC 1876 SIZE mantissa/exponent
794794
// format and returns a string in m (two decimals for the cm).
795-
func cmToM(m, e uint8) string {
795+
func cmToM(x uint8) string {
796+
m := x & 0xf0 >> 4
797+
e := x & 0x0f
798+
796799
if e < 2 {
797800
if e == 1 {
798801
m *= 10
@@ -848,10 +851,9 @@ func (rr *LOC) String() string {
848851
s += fmt.Sprintf("%.0fm ", alt)
849852
}
850853

851-
s += cmToM(rr.Size&0xf0>>4, rr.Size&0x0f) + "m "
852-
s += cmToM(rr.HorizPre&0xf0>>4, rr.HorizPre&0x0f) + "m "
853-
s += cmToM(rr.VertPre&0xf0>>4, rr.VertPre&0x0f) + "m"
854-
854+
s += cmToM(rr.Size) + "m "
855+
s += cmToM(rr.HorizPre) + "m "
856+
s += cmToM(rr.VertPre) + "m"
855857
return s
856858
}
857859

types_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,37 @@ import (
55
)
66

77
func TestCmToM(t *testing.T) {
8-
s := cmToM(0, 0)
8+
s := cmToM((0 << 4) + 0)
99
if s != "0.00" {
1010
t.Error("0, 0")
1111
}
1212

13-
s = cmToM(1, 0)
13+
s = cmToM((1 << 4) + 0)
1414
if s != "0.01" {
1515
t.Error("1, 0")
1616
}
1717

18-
s = cmToM(3, 1)
18+
s = cmToM((3 << 4) + 1)
1919
if s != "0.30" {
2020
t.Error("3, 1")
2121
}
2222

23-
s = cmToM(4, 2)
23+
s = cmToM((4 << 4) + 2)
2424
if s != "4" {
2525
t.Error("4, 2")
2626
}
2727

28-
s = cmToM(5, 3)
28+
s = cmToM((5 << 4) + 3)
2929
if s != "50" {
3030
t.Error("5, 3")
3131
}
3232

33-
s = cmToM(7, 5)
33+
s = cmToM((7 << 4) + 5)
3434
if s != "7000" {
3535
t.Error("7, 5")
3636
}
3737

38-
s = cmToM(9, 9)
38+
s = cmToM((9 << 4) + 9)
3939
if s != "90000000" {
4040
t.Error("9, 9")
4141
}

0 commit comments

Comments
 (0)