Re: ksh: expr 2147483648 / 2 = -1073741824 expected behavior or bug?

2014-02-26 Thread Janne Johansson
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

Re: ksh: expr 2147483648 / 2 = -1073741824 expected behavior or bug?

2014-02-25 Thread Fabian Raetz
On Tue, Feb 25, 2014 at 02:00:49AM +0100, Ingo Schwarze wrote: Hi Fabian, Fabian Raetz wrote on Mon, Feb 24, 2014 at 10:59:34PM +0100: while calculating my phys. memory (mb) with the folllowing shellsript i get as a result -424. sysctl -n hw.physmem returns 3849830400

Re: ksh: expr 2147483648 / 2 = -1073741824 expected behavior or bug?

2014-02-25 Thread pae3
On 02/25/2014 15:43, Fabian Raetz wrote: On Tue, Feb 25, 2014 at 02:00:49AM +0100, Ingo Schwarze wrote: Hi Fabian, Fabian Raetz wrote on Mon, Feb 24, 2014 at 10:59:34PM +0100: while calculating my phys. memory (mb) with the folllowing shellsript i get as a result -424. sysctl -n hw.physmem

Re: ksh: expr 2147483648 / 2 = -1073741824 expected behavior or bug?

2014-02-25 Thread Ingo Schwarze
Hi, pae3 wrote on Tue, Feb 25, 2014 at 04:52:52PM +0400: on my i386 system: $expr 2147483648 + 0 -2147483648 $sh -c 'echo $((2147483648 + 0))' -2147483648 $bash -c 'echo $((2147483648 + 0))' 2147483648 $zsh -c 'echo $((2147483648 + 0))' 2147483648 bug in ksh? No. Assuming you are

Re: ksh: expr 2147483648 / 2 = -1073741824 expected behavior or bug?

2014-02-25 Thread Theo de Raadt
I'm pretty new to shell programming and the behavior required by POSIX makes no sense to me at all how could i ever trust in expr with unknown numbers? Indeed. Sometimes you just can't trust decisions set in stone by POSIX. Sometimes they are just plain broken. If an architecture

ksh: expr 2147483648 / 2 = -1073741824 expected behavior or bug?

2014-02-24 Thread Fabian Raetz
Hi misc@, while calculating my phys. memory (mb) with the folllowing shellsript i get as a result -424. sysctl -n hw.physmem returns 3849830400 #!/bin/sh phys_mem_bytes=`sysctl -n hw.physmem` phys_mem_mb=`expr $phys_mem_bytes / 1024 / 1024` echo $phys_mem_mb -- so i

Re: ksh: expr 2147483648 / 2 = -1073741824 expected behavior or bug?

2014-02-24 Thread Richard Pöttler
On Mon, Feb 24, 2014 at 10:59 PM, Fabian Raetz fabian.ra...@gmail.com wrote: while calculating my phys. memory (mb) with the folllowing shellsript i get as a result -424. sysctl -n hw.physmem returns 3849830400 #!/bin/sh phys_mem_bytes=`sysctl -n hw.physmem`

Re: ksh: expr 2147483648 / 2 = -1073741824 expected behavior or bug?

2014-02-24 Thread Fred
On 02/24/14 22:32, Richard Pöttler wrote: On Mon, Feb 24, 2014 at 10:59 PM, Fabian Raetz fabian.ra...@gmail.com wrote: while calculating my phys. memory (mb) with the folllowing shellsript i get as a result -424. sysctl -n hw.physmem returns 3849830400 #!/bin/sh

Re: ksh: expr 2147483648 / 2 = -1073741824 expected behavior or bug?

2014-02-24 Thread Robert Peichaer
On Mon, Feb 24, 2014 at 11:10:44PM +, Fred wrote: On 02/24/14 22:32, Richard P??ttler wrote: On Mon, Feb 24, 2014 at 10:59 PM, Fabian Raetz fabian.ra...@gmail.com wrote: while calculating my phys. memory (mb) with the folllowing shellsript i get as a result -424. sysctl -n hw.physmem

Re: ksh: expr 2147483648 / 2 = -1073741824 expected behavior or bug?

2014-02-24 Thread Stuart Henderson
On 2014-02-24, Fabian Raetz fabian.ra...@gmail.com wrote: Hi misc@, while calculating my phys. memory (mb) with the folllowing shellsript i get as a result -424. sysctl -n hw.physmem returns 3849830400 #!/bin/sh phys_mem_bytes=`sysctl -n hw.physmem` phys_mem_mb=`expr

Re: ksh: expr 2147483648 / 2 = -1073741824 expected behavior or bug?

2014-02-24 Thread Alexander Hall
On February 25, 2014 12:27:41 AM CET, Stuart Henderson s...@spacehopper.org wrote: On 2014-02-24, Fabian Raetz fabian.ra...@gmail.com wrote: Hi misc@, while calculating my phys. memory (mb) with the folllowing shellsript i get as a result -424. sysctl -n hw.physmem returns 3849830400

Re: ksh: expr 2147483648 / 2 = -1073741824 expected behavior or bug?

2014-02-24 Thread Stuart Henderson
It does for /bin/sh, which is why I suggested perl rather than echo $(($(sysctl -n hw.physmem)/1024/1024)) which will work on 64-bit arch but not 32-bit. On 24 February 2014 23:49:08 GMT+00:00, Alexander Hall alexan...@beard.se wrote: On February 25, 2014 12:27:41 AM CET, Stuart Henderson

Re: ksh: expr 2147483648 / 2 = -1073741824 expected behavior or bug?

2014-02-24 Thread Ingo Schwarze
Hi Fabian, Fabian Raetz wrote on Mon, Feb 24, 2014 at 10:59:34PM +0100: while calculating my phys. memory (mb) with the folllowing shellsript i get as a result -424. sysctl -n hw.physmem returns 3849830400 #!/bin/sh phys_mem_bytes=`sysctl -n hw.physmem`

Re: ksh: expr 2147483648 / 2 = -1073741824 expected behavior or bug?

2014-02-24 Thread Philip Guenther
On Mon, Feb 24, 2014 at 5:00 PM, Ingo Schwarze schwa...@usta.de wrote: ... The above behaviour is required by POSIX: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap01.html#tag_17_01_02_01 Integer variables and constants, including the values of operands and

Re: ksh: expr 2147483648 / 2 = -1073741824 expected behavior or bug?

2014-02-24 Thread Dennis Davis
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