Skip to content

Commit

Permalink
Merge pull request #4 from asnodgrass/bug/rounding-errors
Browse files Browse the repository at this point in the history
Fix floating point rounding errors
  • Loading branch information
asnodgrass authored May 7, 2017
2 parents 0131b41 + 2286470 commit 92dcdbe
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func formatTimeCSV(date v1000.Date) string {
return fmt.Sprintf("%02d%02d%02d", date.Hour, date.Minute, date.Second)
}

func formatLatLon(latLon float32, northSouth bool) string {
func formatLatLon(latLon float64, northSouth bool) string {
x := true
var dir string
if latLon < 0 {
Expand Down
4 changes: 2 additions & 2 deletions cmd/gpx.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ type gpxHeader struct {
}

// latLong ...
type latLong float32
type latLong float64
// other ...
type other float32
type other float64

// MarshalXMLAttr ...
func (value latLong) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
Expand Down
16 changes: 8 additions & 8 deletions v1000/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ type Record struct {
Index uint32
Type string
Time Date
Longitude float32
Longitude float64
South bool
Latitude float32
Latitude float64
West bool
Altitude uint32
Speed float32
Speed float64
Heading uint16
Pressure float32
Pressure float64
Temperature uint16
}

Expand Down Expand Up @@ -160,15 +160,15 @@ func parseCoords(file *os.File, rec *Record) (error) {
if err != nil {
return err
}
rec.Latitude = float32(value) / 1000000.0
rec.Latitude = float64(value) / 1000000.0
if rec.South {
rec.Latitude = -rec.Latitude
}
value, err = parseLong(file)
if err != nil {
return err
}
rec.Longitude = float32(value) / 1000000.0
rec.Longitude = float64(value) / 1000000.0
if rec.West {
rec.Longitude = -rec.Longitude
}
Expand All @@ -189,7 +189,7 @@ func parseSpeed(file *os.File, rec *Record) error {
if err != nil {
return err
}
rec.Speed = float32(value / 10)
rec.Speed = float64(value) / 10.0
return nil
}

Expand All @@ -207,7 +207,7 @@ func parsePressure(file *os.File, rec *Record) error {
if err != nil {
return err
}
rec.Pressure = float32(value / 10)
rec.Pressure = float64(value) / 10.0
return nil
}

Expand Down

0 comments on commit 92dcdbe

Please sign in to comment.