Following on some recent internet discussion on INT_MIN/-1 [0][1], I tried some
examples using ksh. On x86_64, where unrepresentable integer division results
raise a fault,
$ echo $((2**63 / -1))
hangs the shell with 100% cpu, apparently forever retrying the idiv.
I also noticed some other odd behaviour around the int/float boundary:
$ echo ${.sh.version}
Version AJM 93u+ 2012-08-01
$
$ echo $((2 ** 63))
9.22337203685477581e+18
$ echo $((2 ** 63 * 1))
9.22337203685477581e+18
$ echo $((2 ** 63 / 1)) # surprise
-9223372036854775808
$
$ ((n = 2**63))
$ echo $n
9.22337203685477581e+18
$ echo $(((n + 0) / -1))
-9.22337203685477581e+18
$ echo $(((0 + n) / -1)) # surprise
0
$
[0] http://kqueue.org/blog/2012/12/31/idiv-dos/
[1] http://blog.regehr.org/archives/887
--
Kevin Schoedel <[email protected]> VA3TCS
_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users