Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
Don't give an error for 1.0/0 and 0.0/0
Browse files Browse the repository at this point in the history
  • Loading branch information
jyn514 authored and Joshua Nelson committed May 21, 2020
1 parent 091c247 commit a4a2442
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ fn fold_binary(
Mul,
),
Div => {
if right.is_zero() {
if right.ctype.is_integral() && right.is_zero() {
return Err(location.error(SemanticError::DivideByZero));
}
left.literal_bin_op(
Expand Down
12 changes: 12 additions & 0 deletions tests/runner-tests/decls/float-limits.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// output: inf nan
int printf(const char *format, ...);

float INF = 1.0 / 0;
float NaN = 0.0 / 0;

int main() {
// work around bugs in rustc: https://github.com/rust-lang/rust/issues/72411
int NaN_positive_int = (*(int*)&NaN) & 0x7fffffff;
float NaN_positive = *(float*)&NaN_positive_int;
printf("%f %f\n", INF, NaN_positive);
}

0 comments on commit a4a2442

Please sign in to comment.