Skip to content

Commit

Permalink
Merge pull request #78 from olomix/master
Browse files Browse the repository at this point in the history
Fix GetCanonicalDouble for values between -1 and +1
  • Loading branch information
kazarena authored Dec 10, 2024
2 parents 257ca0d + f788b18 commit 19254b3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ld/rdf_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@ func (ds *RDFDataset) GetQuads(graphName string) []*Quad {
return ds.Graphs[graphName]
}

var canonicalDoubleRegEx = regexp.MustCompile(`(\d)0*E\+?0*(\d)`)
var canonicalDoubleRegEx = regexp.MustCompile(`(\d)0*E\+?(-)?0*(\d)`)

// GetCanonicalDouble returns a canonical string representation of a float64 number.
func GetCanonicalDouble(v float64) string {
return canonicalDoubleRegEx.ReplaceAllString(fmt.Sprintf("%1.15E", v), "${1}E${2}")
return canonicalDoubleRegEx.ReplaceAllString(fmt.Sprintf("%1.15E", v), "${1}E${2}${3}")
}

var (
Expand Down
3 changes: 3 additions & 0 deletions ld/rdf_dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ import (

func TestGetCanonicalDouble(t *testing.T) {
assert.Equal(t, "5.3E0", GetCanonicalDouble(5.3))
assert.Equal(t, "-7.5E1", GetCanonicalDouble(-75))
assert.Equal(t, "7.5E-1", GetCanonicalDouble(0.75))
assert.Equal(t, "-7.5E-1", GetCanonicalDouble(-0.75))
}

0 comments on commit 19254b3

Please sign in to comment.