Skip to content
This repository has been archived by the owner on Jan 28, 2019. It is now read-only.

Add NaN, Infinity reader support #126

Merged
merged 3 commits into from
Apr 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Change Log

## Upcoming
- [#126](https://github.com/jaunt-lang/jaunt/pull/126) Add reader support for `Infinity`, `NaN` (@arrdem).
- [#123](https://github.com/jaunt-lang/jaunt/pull/123) Add support for `:jnt` in reader conditionals (@arrdem).
- Update to Java 1.8
- Implement `java.lang.Iterable` over `clojure.lang.Seqable` using a Java 8 interface default method
Expand Down
6 changes: 6 additions & 0 deletions src/jvm/clojure/lang/EdnReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ static private Object interpretToken(String s) {
return RT.T;
} else if (s.equals("false")) {
return RT.F;
} else if (s.equals("NaN")) {
return Double.NaN;
} else if (s.equals("-Infinity")) {
return Double.NEGATIVE_INFINITY;
} else if (s.equals("Infinity") || s.equals("+Infinity")) {
return Double.POSITIVE_INFINITY;
}

Object ret = null;
Expand Down
7 changes: 7 additions & 0 deletions src/jvm/clojure/lang/LispReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,14 @@ static private Object interpretToken(String s) {
return RT.T;
} else if (s.equals("false")) {
return RT.F;
} else if (s.equals("NaN")) {
return Double.NaN;
} else if (s.equals("-Infinity")) {
return Double.NEGATIVE_INFINITY;
} else if (s.equals("Infinity") || s.equals("+Infinity")) {
return Double.POSITIVE_INFINITY;
}

Object ret = null;

ret = matchSymbol(s);
Expand Down
5 changes: 5 additions & 0 deletions test/clojure/test_clojure/reader.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@
(is (instance? Double -1.0))
(is (instance? Double -1.))

(is (instance? Double Infinity))
(is (instance? Double +Infinity))
(is (instance? Double -Infinity))
(is (instance? Double NaN))

; Read BigDecimal
(is (instance? BigDecimal 9223372036854775808M))
(is (instance? BigDecimal -9223372036854775809M))
Expand Down