authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-07-20 17:50:37+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-07-21 22:29:15+03:00
logfd2f034e31bb7b2f8c671158a61473222b5cb332
tree818031596b7565420da82ee61a981e231aa1bcde
parent8ee629aa4c7fb0127c71aec0b2c81353c4291ebb
signaturelock-open Commit is signed but in an unrecognized format.

fix comptime comparisons of different sized floats


2 files changed, 14 insertions(+), 2 deletions(-)

src/ir.cpp+3-2
......@@ -288,6 +288,7 @@ static IrInstGen *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInst* so
288288static bool value_cmp_numeric_val_any(ZigValue *left, Cmp predicate, ZigValue *right);
289289static bool value_cmp_numeric_val_all(ZigValue *left, Cmp predicate, ZigValue *right);
290290static void memoize_field_init_val(CodeGen *codegen, ZigType *container_type, TypeStructField *field);
291static void value_to_bigfloat(BigFloat *out, ZigValue *val);
291292
292293#define ir_assert(OK, SOURCE_INSTRUCTION) ir_assert_impl((OK), (SOURCE_INSTRUCTION), __FILE__, __LINE__)
293294#define ir_assert_gen(OK, SOURCE_INSTRUCTION) ir_assert_gen_impl((OK), (SOURCE_INSTRUCTION), __FILE__, __LINE__)
......@@ -10930,8 +10931,8 @@ static Cmp float_cmp(ZigValue *op1, ZigValue *op2) {
1093010931 }
1093110932 BigFloat op1_big;
1093210933 BigFloat op2_big;
10933 float_init_bigfloat(op1, &op1_big);
10934 float_init_bigfloat(op2, &op2_big);
10934 value_to_bigfloat(&op1_big, op1);
10935 value_to_bigfloat(&op2_big, op2);
1093510936 return bigfloat_cmp(&op1_big, &op2_big);
1093610937}
1093710938
test/stage1/behavior/floatop.zig+11
......@@ -434,6 +434,17 @@ fn testFloatComparisons() void {
434434 }
435435}
436436
437test "different sized float comparisons" {
438 testDifferentSizedFloatComparisons();
439 comptime testDifferentSizedFloatComparisons();
440}
441
442fn testDifferentSizedFloatComparisons() void {
443 var a: f16 = 1;
444 var b: f64 = 2;
445 expect(a < b);
446}
447
437448// TODO This is waiting on library support for the Windows build (not sure why the other's don't need it)
438449//test "@nearbyint" {
439450// comptime testNearbyInt();