Hide Forgot
Description of problem: It Looks like mksh is using a 32-bit register for signed integers, so anything above 2^31 -1 rolls over to a negative value. (Note: 536870912 = 2^29) [root@htest06 ~]# uname -r 2.6.32-220.el6.x86_64 [root@htest06 ~]# rpm -qa mksh mksh-39-7.el6.x86_64 [root@htest06 ~]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.2 (Santiago) [root@htest06 ~]# alternatives --config ksh There is 1 program that provides 'ksh'. Selection Command ----------------------------------------------- *+ 1 /bin/mksh Enter to keep the current selection[+], or type selection number: Version-Release number of selected component (if applicable): RHEL 6.2 How reproducible: Easy to reproduce Steps to Reproduce: $ echo "2^29 = $(( 1 * 536870912 ))" 2^29 = 536870912 $ echo "2^30 = $(( 2 * 536870912 ))" 2^30 = 1073741824 $ echo "2^31 = $(( 4 * 536870912 ))" 2^31 = -2147483648 $ echo "2^31 - 1 = $(( 4 * 536870912 - 1 ))" 2^31 - 1 = 2147483647 Actual results: -2147483648 Expected results: 2147483648 Additional info:
reproducible with mksh(rhel6), not reproducible with pdksh(rhel5)
I talked with upstream and this is expected and documented behaviour: $ man mksh """ Arithmetic expressions ... Expressions are calculated using signed arithmetic and the mksh_ari_t type (a 32-bit signed integer), unless they begin with a sole ‘#’ character, in which case they use mksh_uari_t (a 32-bit unsigned integer). """