Skip to content

Commit

Permalink
fix(eval): Prefer formatting numbers in normal form if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
thesephist committed May 26, 2021
1 parent 65bf742 commit 5d7d5dd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion SPEC.md
Expand Up @@ -30,7 +30,7 @@ Literal: NumberLiteral | StringLiteral
| BooleanLiteral | FunctionLiteral
| ObjectLiteral | ListLiteral
NumberLiteral: (0-9)+ ['.' (0-9)+]
NumberLiteral: (0-9)+ ['.' (0-9)+] ['e' [+-]? (0-9)+]
StringLiteral: '\'' (.*) '\''
BooleanLiteral: 'true' | 'false'
Expand Down
5 changes: 5 additions & 0 deletions pkg/ink/eval.go
Expand Up @@ -33,6 +33,11 @@ func isIntable(n NumberValue) bool {
// Utility func to get a consistent, language spec-compliant
// string representation of numbers
func nToS(f float64) string {
// Prefer exact integer form if possible
if i := int64(f); f == float64(i) {
return strconv.FormatInt(i, 10)
}

return strconv.FormatFloat(f, 'g', -1, 64)
}

Expand Down

0 comments on commit 5d7d5dd

Please sign in to comment.