From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sam Halliday Newsgroups: gmane.emacs.help Subject: calc-eval and lsh/logand of large numbers Date: Mon, 27 Oct 2014 15:58:37 -0700 (PDT) Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1414450825 4755 80.91.229.3 (27 Oct 2014 23:00:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 27 Oct 2014 23:00:25 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Oct 28 00:00:19 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XitGs-0005So-Nv for geh-help-gnu-emacs@m.gmane.org; Tue, 28 Oct 2014 00:00:18 +0100 Original-Received: from localhost ([::1]:36324 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XitGs-0003Hh-Fn for geh-help-gnu-emacs@m.gmane.org; Mon, 27 Oct 2014 19:00:18 -0400 X-Received: by 10.236.14.9 with SMTP id c9mr23093965yhc.18.1414450717810; Mon, 27 Oct 2014 15:58:37 -0700 (PDT) X-Received: by 10.140.88.70 with SMTP id s64mr40630qgd.32.1414450717547; Mon, 27 Oct 2014 15:58:37 -0700 (PDT) Original-Path: usenet.stanford.edu!s7no1030323qap.0!news-out.google.com!u5ni13qab.1!nntp.google.com!u7no604947qaz.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=109.153.118.254; posting-account=kRukCAoAAAANs-vsVh9dFwo5kp5pwnPz Original-NNTP-Posting-Host: 109.153.118.254 User-Agent: G2/1.0 Injection-Date: Mon, 27 Oct 2014 22:58:37 +0000 Original-Xref: usenet.stanford.edu gnu.emacs.help:208354 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:100629 Archived-At: Hi all, I was playing with calc-eval to get a feel for the arbitrary precision supp= ort and decided to see if it could be used to represent a BitSet. If you're= not familiar with the concept, imagine a list of bits and if the N'th bit = is true then the set contains the integer N. It's reasonably efficient at s= toring arbitrary collections of integers: memory requirement is specified b= y the maximum value rather than the number of entries in the set. This looked promising: (require 'calc) (defmath bitIndex (i) (lsh 1 i)) (calc-eval "bitIndex(10)") ; "1024" but when I went to a number that would be shifted beyond the 64 bit length = of an integer it all fell apart (calc-eval "bitIndex(64)") ; "0" I would have expected this to return "18446744073709551616". Is this a known limitation or have I simply not understood something? BTW, if anybody is interested I was planning on doing something like the fo= llowing. If you have a cleaner way of doing this, please let me know as I'l= l be interested to hear about it. The reason I'm doing this is because I am= writing an S-Exp serialisation layer in Scala and this notation works well= for serialising Scala's BitSet's... I was curious to see if I could get it= to work in elisp: https://github.com/fommil/ensime-server/blob/sexp/src/ma= in/scala/org/ensime/sexp/formats/CollectionFormats.scala#L131 (defmath bitsetAnd (bitset i) (logand (lsh 1 i) bitset)) (defun bitsetContains (bitset i) (<=3D 1 (calc-eval "bitsetAnd($, $$)" 'raw bitset i))) (bitsetContains "10#3" 0) ; 't (bitsetContains "10#3" 1) ; 't (bitsetContains "10#3" 2) ; nil (bitsetContains "16#10000000000000000" 64) ; nil (bitsetContains "16#10000000000000001" 0) ; t (bitsetContains "16#10000000000000001" 64) ; t WRONG (bitsetContains "16#10000000000000002" 1) ; t (bitsetContains "16#10000000000000002" 64) ; t WRONG (bitsetContains "16#10000000000000002" 0) ; nil Best regards, Sam