-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Lang] Fix integral type promotion rules (e.g., u8 + u8 now leads to u8 instead of i32) #4789
[Lang] Fix integral type promotion rules (e.g., u8 + u8 now leads to u8 instead of i32) #4789
Conversation
✅ Deploy Preview for docsite-preview canceled.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!!
I was previously stuck at this issue because I thought we must follow C in arithmetic operations. However this is not a necessary assumption...
BTW I think we need to update the doc as well:
taichi/docs/lang/articles/basic/type.md
Line 103 in 022456d
Taichi follows the [implicit conversion rules](https://en.cppreference.com/w/c/language/conversion) for the C programming language and implicitly casts operands in a [binary operation](https://en.wikipedia.org/wiki/Binary_operation) into a *common type* if the operation involves different data types. Following are two most straightforward rules for determining the common type in a binary operation: |
Thank you @strongoier!
I was also stuck a bit here, until I realized that LLVM uses a similar rule as ours: char add(char a, char b) {
return a + b;
} define signext i8 @add(i8 signext %0, i8 signext %1) local_unnamed_addr #0 {
%3 = add i8 %1, %0
ret i8 %3
} Could you help create an issue for the doc update? One more thing I would like to point out: Currently, all binary operators follow the current promotion rule. But there are exceptions. For example, |
…u8 instead of i32) (taichi-dev#4789)
Related issue = closes #4613
Related issue = #2196
It's interesting that in C++
i8 + i8 = i32
.Type promotion table:
Format: a + b = old_type -> new_type. Only some are changed.