Skip to content
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

Assignment of -0 in arithmetic expansion doesn't remove negative sign #781

Open
laurenthuberdeau opened this issue Aug 31, 2024 · 1 comment

Comments

@laurenthuberdeau
Copy link

laurenthuberdeau commented Aug 31, 2024

Assignment of -0 in arithmetic expansion assigns -0 to variables on ARM. ksh on x86 and other shells remove the negative sign, which makes me think it may be due to some undefined behavior like in #770.

This short example shows the bug.

> ksh
$ : $(( a = 0 ))
$ : $(( b = -0 ))
$ : $(( c = +0 ))
$ echo $a # print 0
0
$ echo $b # print -0 instead of 0
-0
$ echo $c # print 0 as expected
0
@ko1nksm
Copy link

ko1nksm commented Sep 5, 2024

Here is another example on Linux on x86_64. I don't think this includes undefined behavior.

$ ksh -c 'v=0; (( v = -1 * v )); echo $v'
-0

This issue may have been introduced between ksh93-2007-06-28 and ksh93-2007-11-05.

root@6eb222d646da:/# ksh93-2007-06-28 -c 'v=0; (( v = -1 * v )); echo $v'
0

root@6eb222d646da:/# ksh93-2007-11-05 -c 'v=0; (( v = -1 * v )); echo $v'
-0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants