-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add negative-zero.c test to document bug
- Loading branch information
1 parent
0348374
commit 9e51438
Showing
3 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// On ksh, when assigning the negative value of a variable containing 0 (i.e. | ||
// -0) to a variable using arithmetic expansion, the variable is assigned the | ||
// string `-0` instead of 0. Other shells assign 0 as expected. | ||
|
||
// expect_failure_for: ksh | ||
int return0() { | ||
int a = 0; | ||
return -a; | ||
} | ||
|
||
void putstring(char *s) { | ||
while (*s) { | ||
putchar(*s); | ||
s = s + 1; | ||
} | ||
} | ||
|
||
void main() { | ||
// Workaround: use `return0() + 0 == 0`. | ||
// This forces the result of return0 to be in an arithmetic expansion which removes the `-` from `-0`. | ||
if (return0() == 0) { | ||
putstring("zero\n"); | ||
} else { | ||
putstring("non-zero\n"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
zero |