[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ast-users
Subject:    [ast-users] ksh  $((2**63 / -1)) hangs on x86_64
From:       schoedel () kw ! igs ! net
Date:       2013-01-30 15:53:17
Message-ID: 20130130154125.M40523 () kw ! igs ! net
[Download RAW message or body]

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 <schoedel@kw.igs.net> VA3TCS

_______________________________________________
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic