On Tue, 25 Feb 2014, Ingo Schwarze wrote: > From: Ingo Schwarze <schwa...@usta.de> > To: Fabian Raetz <fabian.ra...@gmail.com> > Cc: misc@openbsd.org > Date: Tue, 25 Feb 2014 01:00:49 > Subject: Re: ksh: expr 2147483648 / 2 = -1073741824 expected behavior or bug?
... > > so i tried > > expr 2147483647 / 2 which returns 1073741824 while > > expr 2147483648 / 2 returns -1073741824 > > > > ksh(1) states that expr does Integer arithmetic. > > So is this the expected behaviour or a bug? > > How strange, six replies but nobody answered your question... > > The above behaviour is required by POSIX: ... Possibly worth muddying the waters slightly by noting the bash shell on my old i386 box gets the sum right: poulidor $ cat /tmp/t.sh #!/usr/local/bin/bash echo $((2147483647/2)) echo $((2147483648/2)) poulidor $ /tmp/t.sh 1073741823 1073741824 poulidor $ /usr/local/bin/bash --version GNU bash, version 4.2.42(1)-release (i386-unknown-openbsd5.3) Copyright (C) 2011 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Seems like bash is not adhering to the POSIX standard :-) -- Dennis Davis <dennisda...@fastmail.fm>