Skip to content

Commit

Permalink
Value: compare for zero against float instead of Value
Browse files Browse the repository at this point in the history
We can't compare complex values; toFloat grabs just the real part.
This logic will need to be updated when complex int values are supported.

Fixes #675
ehaas committed Apr 8, 2024
1 parent 28ca8ca commit f6df714
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/aro/Value.zig
Original file line number Diff line number Diff line change
@@ -143,7 +143,7 @@ pub fn floatToInt(v: *Value, dest_ty: Type, comp: *Compilation) !FloatToIntChang
v.* = fromBool(!was_zero);
if (was_zero or was_one) return .none;
return .value_changed;
} else if (dest_ty.isUnsignedInt(comp) and v.compare(.lt, zero, comp)) {
} else if (dest_ty.isUnsignedInt(comp) and float_val < 0) {
v.* = zero;
return .out_of_range;
}
1 change: 1 addition & 0 deletions test/cases/complex values.c
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ _Complex double c = (_Complex double) {1.0, 2.0,3.0};

_Static_assert(3 + 4.0il == 3 + 4.0il, "");
_Static_assert(5ll + 4.0il == 5ll + 4.0il, "");
unsigned long complex_integer = 2.0i;

#define EXPECTED_ERRORS "complex values.c:31:49: error: expected expression" \
"complex values.c:32:49: warning: excess elements in scalar initializer [-Wexcess-initializers]" \

0 comments on commit f6df714

Please sign in to comment.