| ... | @@ -119,9 +119,23 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -119,9 +119,23 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 119 | , "Hello, world!\n0012 012 a\n"); | 119 | , "Hello, world!\n0012 012 a\n"); |
| 120 | | 120 | |
| 121 | cases.addC("number literals", | 121 | cases.addC("number literals", |
| 122 | \\const c = @cImport(@cInclude("stdio.h")); | 122 | \\const builtin = @import("builtin"); |
| | 123 | \\const is_windows = builtin.os == builtin.Os.windows; |
| | 124 | \\const c = @cImport({ |
| | 125 | \\ if (is_windows) { |
| | 126 | \\ // See https://github.com/zig-lang/zig/issues/515 |
| | 127 | \\ @cDefine("_NO_CRT_STDIO_INLINE", "1"); |
| | 128 | \\ @cInclude("io.h"); |
| | 129 | \\ @cInclude("fcntl.h"); |
| | 130 | \\ } |
| | 131 | \\ @cInclude("stdio.h"); |
| | 132 | \\}); |
| 123 | \\ | 133 | \\ |
| 124 | \\export fn main(argc: c_int, argv: &&u8) -> c_int { | 134 | \\export fn main(argc: c_int, argv: &&u8) -> c_int { |
| | 135 | \\ if (is_windows) { |
| | 136 | \\ // we want actual \n, not \r\n |
| | 137 | \\ _ = c._setmode(1, c._O_BINARY); |
| | 138 | \\ } |
| 125 | \\ _ = c.printf(c"0: %llu\n", | 139 | \\ _ = c.printf(c"0: %llu\n", |
| 126 | \\ u64(0)); | 140 | \\ u64(0)); |
| 127 | \\ _ = c.printf(c"320402575052271: %llu\n", | 141 | \\ _ = c.printf(c"320402575052271: %llu\n", |
| ... | @@ -143,61 +157,61 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -143,61 +157,61 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 143 | \\ | 157 | \\ |
| 144 | \\ _ = c.printf(c"\n"); | 158 | \\ _ = c.printf(c"\n"); |
| 145 | \\ | 159 | \\ |
| 146 | \\ _ = c.printf(c"0.0: %a\n", | 160 | \\ _ = c.printf(c"0.0: %.013a\n", |
| 147 | \\ f64(0.0)); | 161 | \\ f64(0.0)); |
| 148 | \\ _ = c.printf(c"0e0: %a\n", | 162 | \\ _ = c.printf(c"0e0: %.013a\n", |
| 149 | \\ f64(0e0)); | 163 | \\ f64(0e0)); |
| 150 | \\ _ = c.printf(c"0.0e0: %a\n", | 164 | \\ _ = c.printf(c"0.0e0: %.013a\n", |
| 151 | \\ f64(0.0e0)); | 165 | \\ f64(0.0e0)); |
| 152 | \\ _ = c.printf(c"000000000000000000000000000000000000000000000000000000000.0e0: %a\n", | 166 | \\ _ = c.printf(c"000000000000000000000000000000000000000000000000000000000.0e0: %.013a\n", |
| 153 | \\ f64(000000000000000000000000000000000000000000000000000000000.0e0)); | 167 | \\ f64(000000000000000000000000000000000000000000000000000000000.0e0)); |
| 154 | \\ _ = c.printf(c"0.000000000000000000000000000000000000000000000000000000000e0: %a\n", | 168 | \\ _ = c.printf(c"0.000000000000000000000000000000000000000000000000000000000e0: %.013a\n", |
| 155 | \\ f64(0.000000000000000000000000000000000000000000000000000000000e0)); | 169 | \\ f64(0.000000000000000000000000000000000000000000000000000000000e0)); |
| 156 | \\ _ = c.printf(c"0.0e000000000000000000000000000000000000000000000000000000000: %a\n", | 170 | \\ _ = c.printf(c"0.0e000000000000000000000000000000000000000000000000000000000: %.013a\n", |
| 157 | \\ f64(0.0e000000000000000000000000000000000000000000000000000000000)); | 171 | \\ f64(0.0e000000000000000000000000000000000000000000000000000000000)); |
| 158 | \\ _ = c.printf(c"1.0: %a\n", | 172 | \\ _ = c.printf(c"1.0: %.013a\n", |
| 159 | \\ f64(1.0)); | 173 | \\ f64(1.0)); |
| 160 | \\ _ = c.printf(c"10.0: %a\n", | 174 | \\ _ = c.printf(c"10.0: %.013a\n", |
| 161 | \\ f64(10.0)); | 175 | \\ f64(10.0)); |
| 162 | \\ _ = c.printf(c"10.5: %a\n", | 176 | \\ _ = c.printf(c"10.5: %.013a\n", |
| 163 | \\ f64(10.5)); | 177 | \\ f64(10.5)); |
| 164 | \\ _ = c.printf(c"10.5e5: %a\n", | 178 | \\ _ = c.printf(c"10.5e5: %.013a\n", |
| 165 | \\ f64(10.5e5)); | 179 | \\ f64(10.5e5)); |
| 166 | \\ _ = c.printf(c"10.5e+5: %a\n", | 180 | \\ _ = c.printf(c"10.5e+5: %.013a\n", |
| 167 | \\ f64(10.5e+5)); | 181 | \\ f64(10.5e+5)); |
| 168 | \\ _ = c.printf(c"50.0e-2: %a\n", | 182 | \\ _ = c.printf(c"50.0e-2: %.013a\n", |
| 169 | \\ f64(50.0e-2)); | 183 | \\ f64(50.0e-2)); |
| 170 | \\ _ = c.printf(c"50e-2: %a\n", | 184 | \\ _ = c.printf(c"50e-2: %.013a\n", |
| 171 | \\ f64(50e-2)); | 185 | \\ f64(50e-2)); |
| 172 | \\ | 186 | \\ |
| 173 | \\ _ = c.printf(c"\n"); | 187 | \\ _ = c.printf(c"\n"); |
| 174 | \\ | 188 | \\ |
| 175 | \\ _ = c.printf(c"0x1.0: %a\n", | 189 | \\ _ = c.printf(c"0x1.0: %.013a\n", |
| 176 | \\ f64(0x1.0)); | 190 | \\ f64(0x1.0)); |
| 177 | \\ _ = c.printf(c"0x10.0: %a\n", | 191 | \\ _ = c.printf(c"0x10.0: %.013a\n", |
| 178 | \\ f64(0x10.0)); | 192 | \\ f64(0x10.0)); |
| 179 | \\ _ = c.printf(c"0x100.0: %a\n", | 193 | \\ _ = c.printf(c"0x100.0: %.013a\n", |
| 180 | \\ f64(0x100.0)); | 194 | \\ f64(0x100.0)); |
| 181 | \\ _ = c.printf(c"0x103.0: %a\n", | 195 | \\ _ = c.printf(c"0x103.0: %.013a\n", |
| 182 | \\ f64(0x103.0)); | 196 | \\ f64(0x103.0)); |
| 183 | \\ _ = c.printf(c"0x103.7: %a\n", | 197 | \\ _ = c.printf(c"0x103.7: %.013a\n", |
| 184 | \\ f64(0x103.7)); | 198 | \\ f64(0x103.7)); |
| 185 | \\ _ = c.printf(c"0x103.70: %a\n", | 199 | \\ _ = c.printf(c"0x103.70: %.013a\n", |
| 186 | \\ f64(0x103.70)); | 200 | \\ f64(0x103.70)); |
| 187 | \\ _ = c.printf(c"0x103.70p4: %a\n", | 201 | \\ _ = c.printf(c"0x103.70p4: %.013a\n", |
| 188 | \\ f64(0x103.70p4)); | 202 | \\ f64(0x103.70p4)); |
| 189 | \\ _ = c.printf(c"0x103.70p5: %a\n", | 203 | \\ _ = c.printf(c"0x103.70p5: %.013a\n", |
| 190 | \\ f64(0x103.70p5)); | 204 | \\ f64(0x103.70p5)); |
| 191 | \\ _ = c.printf(c"0x103.70p+5: %a\n", | 205 | \\ _ = c.printf(c"0x103.70p+5: %.013a\n", |
| 192 | \\ f64(0x103.70p+5)); | 206 | \\ f64(0x103.70p+5)); |
| 193 | \\ _ = c.printf(c"0x103.70p-5: %a\n", | 207 | \\ _ = c.printf(c"0x103.70p-5: %.013a\n", |
| 194 | \\ f64(0x103.70p-5)); | 208 | \\ f64(0x103.70p-5)); |
| 195 | \\ | 209 | \\ |
| 196 | \\ _ = c.printf(c"\n"); | 210 | \\ _ = c.printf(c"\n"); |
| 197 | \\ | 211 | \\ |
| 198 | \\ _ = c.printf(c"0b10100.00010e0: %a\n", | 212 | \\ _ = c.printf(c"0b10100.00010e0: %.013a\n", |
| 199 | \\ f64(0b10100.00010e0)); | 213 | \\ f64(0b10100.00010e0)); |
| 200 | \\ _ = c.printf(c"0o10700.00010e0: %a\n", | 214 | \\ _ = c.printf(c"0o10700.00010e0: %.013a\n", |
| 201 | \\ f64(0o10700.00010e0)); | 215 | \\ f64(0o10700.00010e0)); |
| 202 | \\ | 216 | \\ |
| 203 | \\ return 0; | 217 | \\ return 0; |
| ... | @@ -213,33 +227,33 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -213,33 +227,33 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 213 | \\0b1111111111111111111111111111111111111111111111111111111111111111: 18446744073709551615 | 227 | \\0b1111111111111111111111111111111111111111111111111111111111111111: 18446744073709551615 |
| 214 | \\0b0000001111111111111111111111111111111111111111111111111111111111111111: 18446744073709551615 | 228 | \\0b0000001111111111111111111111111111111111111111111111111111111111111111: 18446744073709551615 |
| 215 | \\ | 229 | \\ |
| 216 | \\0.0: 0x0p+0 | 230 | \\0.0: 0x0.0000000000000p+0 |
| 217 | \\0e0: 0x0p+0 | 231 | \\0e0: 0x0.0000000000000p+0 |
| 218 | \\0.0e0: 0x0p+0 | 232 | \\0.0e0: 0x0.0000000000000p+0 |
| 219 | \\000000000000000000000000000000000000000000000000000000000.0e0: 0x0p+0 | 233 | \\000000000000000000000000000000000000000000000000000000000.0e0: 0x0.0000000000000p+0 |
| 220 | \\0.000000000000000000000000000000000000000000000000000000000e0: 0x0p+0 | 234 | \\0.000000000000000000000000000000000000000000000000000000000e0: 0x0.0000000000000p+0 |
| 221 | \\0.0e000000000000000000000000000000000000000000000000000000000: 0x0p+0 | 235 | \\0.0e000000000000000000000000000000000000000000000000000000000: 0x0.0000000000000p+0 |
| 222 | \\1.0: 0x1p+0 | 236 | \\1.0: 0x1.0000000000000p+0 |
| 223 | \\10.0: 0x1.4p+3 | 237 | \\10.0: 0x1.4000000000000p+3 |
| 224 | \\10.5: 0x1.5p+3 | 238 | \\10.5: 0x1.5000000000000p+3 |
| 225 | \\10.5e5: 0x1.0059p+20 | 239 | \\10.5e5: 0x1.0059000000000p+20 |
| 226 | \\10.5e+5: 0x1.0059p+20 | 240 | \\10.5e+5: 0x1.0059000000000p+20 |
| 227 | \\50.0e-2: 0x1p-1 | 241 | \\50.0e-2: 0x1.0000000000000p-1 |
| 228 | \\50e-2: 0x1p-1 | 242 | \\50e-2: 0x1.0000000000000p-1 |
| 229 | \\ | 243 | \\ |
| 230 | \\0x1.0: 0x1p+0 | 244 | \\0x1.0: 0x1.0000000000000p+0 |
| 231 | \\0x10.0: 0x1p+4 | 245 | \\0x10.0: 0x1.0000000000000p+4 |
| 232 | \\0x100.0: 0x1p+8 | 246 | \\0x100.0: 0x1.0000000000000p+8 |
| 233 | \\0x103.0: 0x1.03p+8 | 247 | \\0x103.0: 0x1.0300000000000p+8 |
| 234 | \\0x103.7: 0x1.037p+8 | 248 | \\0x103.7: 0x1.0370000000000p+8 |
| 235 | \\0x103.70: 0x1.037p+8 | 249 | \\0x103.70: 0x1.0370000000000p+8 |
| 236 | \\0x103.70p4: 0x1.037p+12 | 250 | \\0x103.70p4: 0x1.0370000000000p+12 |
| 237 | \\0x103.70p5: 0x1.037p+13 | 251 | \\0x103.70p5: 0x1.0370000000000p+13 |
| 238 | \\0x103.70p+5: 0x1.037p+13 | 252 | \\0x103.70p+5: 0x1.0370000000000p+13 |
| 239 | \\0x103.70p-5: 0x1.037p+3 | 253 | \\0x103.70p-5: 0x1.0370000000000p+3 |
| 240 | \\ | 254 | \\ |
| 241 | \\0b10100.00010e0: 0x1.41p+4 | 255 | \\0b10100.00010e0: 0x1.4100000000000p+4 |
| 242 | \\0o10700.00010e0: 0x1.1c0001p+12 | 256 | \\0o10700.00010e0: 0x1.1c00010000000p+12 |
| 243 | \\ | 257 | \\ |
| 244 | ); | 258 | ); |
| 245 | | 259 | |
| ... | @@ -289,8 +303,23 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -289,8 +303,23 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 289 | , ""); | 303 | , ""); |
| 290 | | 304 | |
| 291 | cases.addC("casting between float and integer types", | 305 | cases.addC("casting between float and integer types", |
| 292 | \\const c = @cImport(@cInclude("stdio.h")); | 306 | \\const builtin = @import("builtin"); |
| | 307 | \\const is_windows = builtin.os == builtin.Os.windows; |
| | 308 | \\const c = @cImport({ |
| | 309 | \\ if (is_windows) { |
| | 310 | \\ // See https://github.com/zig-lang/zig/issues/515 |
| | 311 | \\ @cDefine("_NO_CRT_STDIO_INLINE", "1"); |
| | 312 | \\ @cInclude("io.h"); |
| | 313 | \\ @cInclude("fcntl.h"); |
| | 314 | \\ } |
| | 315 | \\ @cInclude("stdio.h"); |
| | 316 | \\}); |
| | 317 | \\ |
| 293 | \\export fn main(argc: c_int, argv: &&u8) -> c_int { | 318 | \\export fn main(argc: c_int, argv: &&u8) -> c_int { |
| | 319 | \\ if (is_windows) { |
| | 320 | \\ // we want actual \n, not \r\n |
| | 321 | \\ _ = c._setmode(1, c._O_BINARY); |
| | 322 | \\ } |
| 294 | \\ const small: f32 = 3.25; | 323 | \\ const small: f32 = 3.25; |
| 295 | \\ const x: f64 = small; | 324 | \\ const x: f64 = small; |
| 296 | \\ const y = i32(x); | 325 | \\ const y = i32(x); |