aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-01-31 21:22:05 -0700
committerAndrew Kelley <superjoe30@gmail.com>2016-01-31 21:22:05 -0700
commita4e19f94f10445273b977e21e721d236a37c5cf4 (patch)
tree842e06c40599c418b67553dfa6859c3dfcf220bc /src/analyze.cpp
parente74a7264ad3b221dfef0c959c1fdd6275f7c70ef (diff)
downloadzig-a4e19f94f10445273b977e21e721d236a37c5cf4.tar.gz
zig-a4e19f94f10445273b977e21e721d236a37c5cf4.zip
support casting between floats
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 785bad9ff2..8942746e2d 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -1681,6 +1681,14 @@ static bool types_match_with_implicit_cast(CodeGen *g, TypeTableEntry *expected_
return true;
}
+ // implicit float widening conversion
+ if (expected_type->id == TypeTableEntryIdFloat &&
+ actual_type->id == TypeTableEntryIdFloat &&
+ expected_type->size_in_bits >= actual_type->size_in_bits)
+ {
+ return true;
+ }
+
// implicit constant sized array to unknown size array conversion
if (expected_type->id == TypeTableEntryIdStruct &&
expected_type->data.structure.is_unknown_size_array &&
@@ -3366,7 +3374,7 @@ static void eval_const_expr_implicit_cast(CodeGen *g, AstNode *node, AstNode *ex
case CastOpNoCast:
zig_unreachable();
case CastOpNoop:
- case CastOpIntWidenOrShorten:
+ case CastOpWidenOrShorten:
case CastOpPointerReinterpret:
*const_val = *other_val;
break;
@@ -3477,11 +3485,13 @@ static TypeTableEntry *analyze_cast_expr(CodeGen *g, ImportTableEntry *import, B
return wanted_type;
}
- // explicit cast from any int to any other int
- if (wanted_type->id == TypeTableEntryIdInt &&
- actual_type->id == TypeTableEntryIdInt)
+ // explicit widening or shortening cast
+ if ((wanted_type->id == TypeTableEntryIdInt &&
+ actual_type->id == TypeTableEntryIdInt) ||
+ (wanted_type->id == TypeTableEntryIdFloat &&
+ actual_type->id == TypeTableEntryIdFloat))
{
- node->data.fn_call_expr.cast_op = CastOpIntWidenOrShorten;
+ node->data.fn_call_expr.cast_op = CastOpWidenOrShorten;
eval_const_expr_implicit_cast(g, node, expr_node);
return wanted_type;
}