aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMarc Tiehuis <marctiehuis@gmail.com>2017-08-07 18:06:06 +1200
committerMarc Tiehuis <marctiehuis@gmail.com>2017-08-07 18:08:09 +1200
commit0705b711f8dd447f4eb4f1517be985ce09bce22f (patch)
treef1285716b6bce9a6ba538808c4825fb86a8e6024 /test
parentd8227c79a2ff7882a52bf53f9ded2db4e7081fc8 (diff)
downloadzig-0705b711f8dd447f4eb4f1517be985ce09bce22f.tar.gz
zig-0705b711f8dd447f4eb4f1517be985ce09bce22f.zip
Correct floating-point literal allowed ranges
The exponent range for floating-point values is [-1022, 1023]. Fixes #399.
Diffstat (limited to 'test')
-rw-r--r--test/cases/math.zig6
-rw-r--r--test/compile_errors.zig14
2 files changed, 20 insertions, 0 deletions
diff --git a/test/cases/math.zig b/test/cases/math.zig
index 33708bd0d6..2bdeb3f3b8 100644
--- a/test/cases/math.zig
+++ b/test/cases/math.zig
@@ -251,3 +251,9 @@ test "allow signed integer division/remainder when values are comptime known and
test "float literal parsing" {
comptime assert(0x1.0 == 1.0);
}
+
+test "hex float literal within range" {
+ const a = 0x1.0p1023;
+ const b = 0x0.1p1027;
+ const c = 0x1.0p-1022;
+}
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
index e4b42b12a4..c78d17a916 100644
--- a/test/compile_errors.zig
+++ b/test/compile_errors.zig
@@ -1931,4 +1931,18 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\}
,
".tmp_source.zig:1:13: error: struct 'Foo' contains itself");
+
+ cases.add("float literal too large error",
+ \\comptime {
+ \\ const a = 0x1.0p1024;
+ \\}
+ ,
+ ".tmp_source.zig:2:15: error: float literal out of range of any type");
+
+ cases.add("float literal too small error (denormal)",
+ \\comptime {
+ \\ const a = 0x1.0p-1023;
+ \\}
+ ,
+ ".tmp_source.zig:2:15: error: float literal out of range of any type");
}