Commit d6bfa3f639
Changed files (1)
test/compare_output.zig
@@ -119,9 +119,23 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
, "Hello, world!\n0012 012 a\n");
cases.addC("number literals",
- \\const c = @cImport(@cInclude("stdio.h"));
+ \\const builtin = @import("builtin");
+ \\const is_windows = builtin.os == builtin.Os.windows;
+ \\const c = @cImport({
+ \\ if (is_windows) {
+ \\ // See https://github.com/zig-lang/zig/issues/515
+ \\ @cDefine("_NO_CRT_STDIO_INLINE", "1");
+ \\ @cInclude("io.h");
+ \\ @cInclude("fcntl.h");
+ \\ }
+ \\ @cInclude("stdio.h");
+ \\});
\\
\\export fn main(argc: c_int, argv: &&u8) -> c_int {
+ \\ if (is_windows) {
+ \\ // we want actual \n, not \r\n
+ \\ _ = c._setmode(1, c._O_BINARY);
+ \\ }
\\ _ = c.printf(c"0: %llu\n",
\\ u64(0));
\\ _ = c.printf(c"320402575052271: %llu\n",
@@ -143,61 +157,61 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\
\\ _ = c.printf(c"\n");
\\
- \\ _ = c.printf(c"0.0: %a\n",
+ \\ _ = c.printf(c"0.0: %.013a\n",
\\ f64(0.0));
- \\ _ = c.printf(c"0e0: %a\n",
+ \\ _ = c.printf(c"0e0: %.013a\n",
\\ f64(0e0));
- \\ _ = c.printf(c"0.0e0: %a\n",
+ \\ _ = c.printf(c"0.0e0: %.013a\n",
\\ f64(0.0e0));
- \\ _ = c.printf(c"000000000000000000000000000000000000000000000000000000000.0e0: %a\n",
+ \\ _ = c.printf(c"000000000000000000000000000000000000000000000000000000000.0e0: %.013a\n",
\\ f64(000000000000000000000000000000000000000000000000000000000.0e0));
- \\ _ = c.printf(c"0.000000000000000000000000000000000000000000000000000000000e0: %a\n",
+ \\ _ = c.printf(c"0.000000000000000000000000000000000000000000000000000000000e0: %.013a\n",
\\ f64(0.000000000000000000000000000000000000000000000000000000000e0));
- \\ _ = c.printf(c"0.0e000000000000000000000000000000000000000000000000000000000: %a\n",
+ \\ _ = c.printf(c"0.0e000000000000000000000000000000000000000000000000000000000: %.013a\n",
\\ f64(0.0e000000000000000000000000000000000000000000000000000000000));
- \\ _ = c.printf(c"1.0: %a\n",
+ \\ _ = c.printf(c"1.0: %.013a\n",
\\ f64(1.0));
- \\ _ = c.printf(c"10.0: %a\n",
+ \\ _ = c.printf(c"10.0: %.013a\n",
\\ f64(10.0));
- \\ _ = c.printf(c"10.5: %a\n",
+ \\ _ = c.printf(c"10.5: %.013a\n",
\\ f64(10.5));
- \\ _ = c.printf(c"10.5e5: %a\n",
+ \\ _ = c.printf(c"10.5e5: %.013a\n",
\\ f64(10.5e5));
- \\ _ = c.printf(c"10.5e+5: %a\n",
+ \\ _ = c.printf(c"10.5e+5: %.013a\n",
\\ f64(10.5e+5));
- \\ _ = c.printf(c"50.0e-2: %a\n",
+ \\ _ = c.printf(c"50.0e-2: %.013a\n",
\\ f64(50.0e-2));
- \\ _ = c.printf(c"50e-2: %a\n",
+ \\ _ = c.printf(c"50e-2: %.013a\n",
\\ f64(50e-2));
\\
\\ _ = c.printf(c"\n");
\\
- \\ _ = c.printf(c"0x1.0: %a\n",
+ \\ _ = c.printf(c"0x1.0: %.013a\n",
\\ f64(0x1.0));
- \\ _ = c.printf(c"0x10.0: %a\n",
+ \\ _ = c.printf(c"0x10.0: %.013a\n",
\\ f64(0x10.0));
- \\ _ = c.printf(c"0x100.0: %a\n",
+ \\ _ = c.printf(c"0x100.0: %.013a\n",
\\ f64(0x100.0));
- \\ _ = c.printf(c"0x103.0: %a\n",
+ \\ _ = c.printf(c"0x103.0: %.013a\n",
\\ f64(0x103.0));
- \\ _ = c.printf(c"0x103.7: %a\n",
+ \\ _ = c.printf(c"0x103.7: %.013a\n",
\\ f64(0x103.7));
- \\ _ = c.printf(c"0x103.70: %a\n",
+ \\ _ = c.printf(c"0x103.70: %.013a\n",
\\ f64(0x103.70));
- \\ _ = c.printf(c"0x103.70p4: %a\n",
+ \\ _ = c.printf(c"0x103.70p4: %.013a\n",
\\ f64(0x103.70p4));
- \\ _ = c.printf(c"0x103.70p5: %a\n",
+ \\ _ = c.printf(c"0x103.70p5: %.013a\n",
\\ f64(0x103.70p5));
- \\ _ = c.printf(c"0x103.70p+5: %a\n",
+ \\ _ = c.printf(c"0x103.70p+5: %.013a\n",
\\ f64(0x103.70p+5));
- \\ _ = c.printf(c"0x103.70p-5: %a\n",
+ \\ _ = c.printf(c"0x103.70p-5: %.013a\n",
\\ f64(0x103.70p-5));
\\
\\ _ = c.printf(c"\n");
\\
- \\ _ = c.printf(c"0b10100.00010e0: %a\n",
+ \\ _ = c.printf(c"0b10100.00010e0: %.013a\n",
\\ f64(0b10100.00010e0));
- \\ _ = c.printf(c"0o10700.00010e0: %a\n",
+ \\ _ = c.printf(c"0o10700.00010e0: %.013a\n",
\\ f64(0o10700.00010e0));
\\
\\ return 0;
@@ -213,33 +227,33 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\0b1111111111111111111111111111111111111111111111111111111111111111: 18446744073709551615
\\0b0000001111111111111111111111111111111111111111111111111111111111111111: 18446744073709551615
\\
- \\0.0: 0x0p+0
- \\0e0: 0x0p+0
- \\0.0e0: 0x0p+0
- \\000000000000000000000000000000000000000000000000000000000.0e0: 0x0p+0
- \\0.000000000000000000000000000000000000000000000000000000000e0: 0x0p+0
- \\0.0e000000000000000000000000000000000000000000000000000000000: 0x0p+0
- \\1.0: 0x1p+0
- \\10.0: 0x1.4p+3
- \\10.5: 0x1.5p+3
- \\10.5e5: 0x1.0059p+20
- \\10.5e+5: 0x1.0059p+20
- \\50.0e-2: 0x1p-1
- \\50e-2: 0x1p-1
+ \\0.0: 0x0.0000000000000p+0
+ \\0e0: 0x0.0000000000000p+0
+ \\0.0e0: 0x0.0000000000000p+0
+ \\000000000000000000000000000000000000000000000000000000000.0e0: 0x0.0000000000000p+0
+ \\0.000000000000000000000000000000000000000000000000000000000e0: 0x0.0000000000000p+0
+ \\0.0e000000000000000000000000000000000000000000000000000000000: 0x0.0000000000000p+0
+ \\1.0: 0x1.0000000000000p+0
+ \\10.0: 0x1.4000000000000p+3
+ \\10.5: 0x1.5000000000000p+3
+ \\10.5e5: 0x1.0059000000000p+20
+ \\10.5e+5: 0x1.0059000000000p+20
+ \\50.0e-2: 0x1.0000000000000p-1
+ \\50e-2: 0x1.0000000000000p-1
\\
- \\0x1.0: 0x1p+0
- \\0x10.0: 0x1p+4
- \\0x100.0: 0x1p+8
- \\0x103.0: 0x1.03p+8
- \\0x103.7: 0x1.037p+8
- \\0x103.70: 0x1.037p+8
- \\0x103.70p4: 0x1.037p+12
- \\0x103.70p5: 0x1.037p+13
- \\0x103.70p+5: 0x1.037p+13
- \\0x103.70p-5: 0x1.037p+3
+ \\0x1.0: 0x1.0000000000000p+0
+ \\0x10.0: 0x1.0000000000000p+4
+ \\0x100.0: 0x1.0000000000000p+8
+ \\0x103.0: 0x1.0300000000000p+8
+ \\0x103.7: 0x1.0370000000000p+8
+ \\0x103.70: 0x1.0370000000000p+8
+ \\0x103.70p4: 0x1.0370000000000p+12
+ \\0x103.70p5: 0x1.0370000000000p+13
+ \\0x103.70p+5: 0x1.0370000000000p+13
+ \\0x103.70p-5: 0x1.0370000000000p+3
\\
- \\0b10100.00010e0: 0x1.41p+4
- \\0o10700.00010e0: 0x1.1c0001p+12
+ \\0b10100.00010e0: 0x1.4100000000000p+4
+ \\0o10700.00010e0: 0x1.1c00010000000p+12
\\
);
@@ -289,8 +303,23 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
, "");
cases.addC("casting between float and integer types",
- \\const c = @cImport(@cInclude("stdio.h"));
+ \\const builtin = @import("builtin");
+ \\const is_windows = builtin.os == builtin.Os.windows;
+ \\const c = @cImport({
+ \\ if (is_windows) {
+ \\ // See https://github.com/zig-lang/zig/issues/515
+ \\ @cDefine("_NO_CRT_STDIO_INLINE", "1");
+ \\ @cInclude("io.h");
+ \\ @cInclude("fcntl.h");
+ \\ }
+ \\ @cInclude("stdio.h");
+ \\});
+ \\
\\export fn main(argc: c_int, argv: &&u8) -> c_int {
+ \\ if (is_windows) {
+ \\ // we want actual \n, not \r\n
+ \\ _ = c._setmode(1, c._O_BINARY);
+ \\ }
\\ const small: f32 = 3.25;
\\ const x: f64 = small;
\\ const y = i32(x);