Skip to content

Commit

Permalink
Allow ^ in constant numeric expressions (#14951)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil authored Sep 3, 2024
1 parent 281fc32 commit 598931c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions spec/compiler/codegen/c_enum_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,22 @@ describe "Code gen: c enum" do
end

[
{"+1", 1},
{"-1", -1},
{"~1", -2},
{"1 + 2", 3},
{"3 - 2", 1},
{"3 * 2", 6},
{"1 &+ 2", 3},
{"3 &- 2", 1},
{"3 &* 2", 6},
# {"10 / 2", 5}, # MathInterpreter only works with Integer and 10 / 2 : Float
{"10 // 2", 5},
{"1 << 3", 8},
{"100 >> 3", 12},
{"10 & 3", 2},
{"10 | 3", 11},
{"10 ^ 3", 9},
{"(1 + 2) * 3", 9},
{"10 % 3", 1},
].each do |(code, expected)|
Expand Down
1 change: 1 addition & 0 deletions src/compiler/crystal/semantic/math_interpreter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct Crystal::MathInterpreter
when "//" then left // right
when "&" then left & right
when "|" then left | right
when "^" then left ^ right
when "<<" then left << right
when ">>" then left >> right
when "%" then left % right
Expand Down

0 comments on commit 598931c

Please sign in to comment.