| author | |
| committer | |
| log | 895aea0b630df97edbbcf68bfad251968c9b9fbf |
| tree | 8ff1152e5f318976d9835c15cc40c0ef66131243 |
| parent | 0a6851cc6de540ed95c3ec1c78eb3da7897bd930 |
There was a typo and they were backwards.3 files changed, 31 insertions(+), 31 deletions(-)
src/Sema.zig+2-2| ... | @@ -9561,8 +9561,8 @@ fn zirIntToFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -9561,8 +9561,8 @@ fn zirIntToFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 9561 | const operand = sema.resolveInst(extra.rhs); | 9561 | const operand = sema.resolveInst(extra.rhs); |
| 9562 | const operand_ty = sema.typeOf(operand); | 9562 | const operand_ty = sema.typeOf(operand); |
| 9563 | 9563 | ||
| 9564 | _ = try sema.checkIntType(block, ty_src, dest_ty); | 9564 | try sema.checkFloatType(block, ty_src, dest_ty); |
| 9565 | try sema.checkFloatType(block, operand_src, operand_ty); | 9565 | _ = try sema.checkIntType(block, operand_src, operand_ty); |
| 9566 | 9566 | ||
| 9567 | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { | 9567 | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { |
| 9568 | const target = sema.mod.getTarget(); | 9568 | const target = sema.mod.getTarget(); |
test/behavior/cast.zig+29| ... | @@ -77,3 +77,32 @@ test "pointer reinterpret const float to int" { | ... | @@ -77,3 +77,32 @@ test "pointer reinterpret const float to int" { |
| 77 | else | 77 | else |
| 78 | try expect(int_val == 0x3fe33333); | 78 | try expect(int_val == 0x3fe33333); |
| 79 | } | 79 | } |
| 80 | |||
| 81 | test "comptime_int @intToFloat" { | ||
| 82 | { | ||
| 83 | const result = @intToFloat(f16, 1234); | ||
| 84 | try expect(@TypeOf(result) == f16); | ||
| 85 | try expect(result == 1234.0); | ||
| 86 | } | ||
| 87 | { | ||
| 88 | const result = @intToFloat(f32, 1234); | ||
| 89 | try expect(@TypeOf(result) == f32); | ||
| 90 | try expect(result == 1234.0); | ||
| 91 | } | ||
| 92 | { | ||
| 93 | const result = @intToFloat(f64, 1234); | ||
| 94 | try expect(@TypeOf(result) == f64); | ||
| 95 | try expect(result == 1234.0); | ||
| 96 | } | ||
| 97 | { | ||
| 98 | const result = @intToFloat(f128, 1234); | ||
| 99 | try expect(@TypeOf(result) == f128); | ||
| 100 | try expect(result == 1234.0); | ||
| 101 | } | ||
| 102 | // big comptime_int (> 64 bits) to f128 conversion | ||
| 103 | { | ||
| 104 | const result = @intToFloat(f128, 0x1_0000_0000_0000_0000); | ||
| 105 | try expect(@TypeOf(result) == f128); | ||
| 106 | try expect(result == 0x1_0000_0000_0000_0000.0); | ||
| 107 | } | ||
| 108 | } |
test/behavior/cast_stage1.zig-29| ... | @@ -356,35 +356,6 @@ test "vector casts" { | ... | @@ -356,35 +356,6 @@ test "vector casts" { |
| 356 | comptime try S.doTheTestFloat(); | 356 | comptime try S.doTheTestFloat(); |
| 357 | } | 357 | } |
| 358 | 358 | ||
| 359 | test "comptime_int @intToFloat" { | ||
| 360 | { | ||
| 361 | const result = @intToFloat(f16, 1234); | ||
| 362 | try expect(@TypeOf(result) == f16); | ||
| 363 | try expect(result == 1234.0); | ||
| 364 | } | ||
| 365 | { | ||
| 366 | const result = @intToFloat(f32, 1234); | ||
| 367 | try expect(@TypeOf(result) == f32); | ||
| 368 | try expect(result == 1234.0); | ||
| 369 | } | ||
| 370 | { | ||
| 371 | const result = @intToFloat(f64, 1234); | ||
| 372 | try expect(@TypeOf(result) == f64); | ||
| 373 | try expect(result == 1234.0); | ||
| 374 | } | ||
| 375 | { | ||
| 376 | const result = @intToFloat(f128, 1234); | ||
| 377 | try expect(@TypeOf(result) == f128); | ||
| 378 | try expect(result == 1234.0); | ||
| 379 | } | ||
| 380 | // big comptime_int (> 64 bits) to f128 conversion | ||
| 381 | { | ||
| 382 | const result = @intToFloat(f128, 0x1_0000_0000_0000_0000); | ||
| 383 | try expect(@TypeOf(result) == f128); | ||
| 384 | try expect(result == 0x1_0000_0000_0000_0000.0); | ||
| 385 | } | ||
| 386 | } | ||
| 387 | |||
| 388 | test "@floatCast cast down" { | 359 | test "@floatCast cast down" { |
| 389 | { | 360 | { |
| 390 | var double: f64 = 0.001534; | 361 | var double: f64 = 0.001534; |