From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?ISO-8859-1?Q?R=FCdiger?= Sonderfeld Subject: Re: Bug: Babel calc sqrt float var Date: Tue, 10 Dec 2013 13:38:24 +0100 Message-ID: <4230137.vUWmcjrSE4@descartes> References: <1386672182.64210.YahooMailNeo@web171906.mail.ir2.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:50240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VqMaO-0007np-6P for emacs-orgmode@gnu.org; Tue, 10 Dec 2013 07:38:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VqMaG-0006H6-Nl for emacs-orgmode@gnu.org; Tue, 10 Dec 2013 07:38:48 -0500 Received: from ptmx.org ([178.63.28.110]:42020) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VqMaG-0006Gq-EL for emacs-orgmode@gnu.org; Tue, 10 Dec 2013 07:38:40 -0500 In-Reply-To: <1386672182.64210.YahooMailNeo@web171906.mail.ir2.yahoo.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org, Miguel Ruiz Hi, the problem is that calc does not operate on regular elisp types but in= stead=20 uses a different format: (float NUM EXP) for decimal floats. But ob-c= alc.el=20 seems to simply push any value it gets on the stack and assigns it to a= =20 variable. And since calc treats anything which isn't in such a lisp fo= rm as=20 an integer it tries to call idiv. To fix this the value should be converted to calc format before `calc-p= ush- list' is called. But after a quick look into calc.el I couldn't find a= ny=20 generic function to convert elisp values to calc values. The function = `math- read-number' seems to be the only way and it requires a string. Howeve= r my=20 knowledge of calc internals is rather limited. Regards, R=C3=BCdiger On Tuesday 10 December 2013 10:43:02 Miguel Ruiz wrote: > Hi, >=20 > Please, I am communicating the following problematic behaviour: >=20 > #------------------- problematic code ------------------------ > #+begin_src calc=20 >=20 > sqrt(0.8) > #+end_src >=20 > #+RESULTS: > : 0.894427191 # OK >=20 > #+begin_src calc :var x=3D0.8 > sqrt(x) > #+end_src >=20 > #+RESULTS: > =3DDebugger entered--Lisp error: (wrong-type-argument integer-or-mark= er-p > 0.80000000000000004) math-idivmod(0.80000000000000004 0.8000000000000= 0004) > math-div(0.80000000000000004 0.80000000000000004) > math-cancel-common-factor(0.80000000000000004 0.80000000000000004) > math-simplify-sqrt() > #[(math-simplify-expr) "\300 \207" [math-simplify-sqrt] 1]((calcFun= c-sqrt > 0.80000000000000004)) math-simplify-step((calcFunc-sqrt > 0.80000000000000004)) > math-simplify((calcFunc-sqrt 0.80000000000000004)) > calc-normalize-fancy((calcFunc-sqrt 0.80000000000000004)) > calc-normalize((calcFunc-sqrt 0.80000000000000004)) > math-evaluate-expr((calcFunc-sqrt 0.80000000000000004)) > #[(line) " > not copy-yank-able string > " > [line var-names calc-mode-map res x 0 calc-recall intern 1 "'" lookup= -key > nil calc-push-list calc-eval math-read-number error "Calc error \"%s\= " on > input \"%s\"" replace-regexp-in-string "" math-evaluate-expr mapcar > org-babel-calc-maybe-resolve-var math-read-exprs] 11] ("sqrt(x)")) > org-babel-execute:calc("sqrt(x)" ((:comments . "") (:shebang . "") (:= cache > . "no") (:padline . "") (:noweb . "no") (:tangle . "no") (:exports . > "code") (:results . "replace") (:var x . 0.80000000000000004) (:sessi= on . > "none") (:hlines . "no") (:result-type . value) (:result-params "repl= ace") > (:rowname-names) (:colname-names))) org-babel-execute-src-block(nil) > org-babel-execute-src-block-maybe() > org-babel-execute-maybe() > org-babel-execute-safely-maybe() > run-hook-with-args-until-success(org-babel-execute-safely-maybe) > org-ctrl-c-ctrl-c(nil) > call-interactively(org-ctrl-c-ctrl-c nil nil) >=20 >=20 > #---------------------- end of problematic code > -------------------------------- >=20 > Command line: emacs -Q -l minimal-org.el >=20 > ;;; minimal-org.el: > ;;; Minimal setup to load latest `org-mode' > =20 > ;; activate debugging > (setq debug-on-error t > debug-on-signal nil > debug-on-quit nil) > =20 > ;; add latest org-mode to load path > (add-to-list 'load-path (expand-file-name "~/org-mode/maint/lisp")) > (add-to-list 'load-path (expand-file-name "~/org-mode/maint/contrib/l= isp" > t)) >=20 > ;; active Babel languages > (org-babel-do-load-languages > 'org-babel-load-languages > '((calc . t))) >=20 > ;;; end of minimal-org.el >=20 > GNU Emacs 24.3.1 (i686-pc-cygwin) of 2013-08-14 on moufang >=20 > Org-mode version 8.2.4 (release_8.2.4-3-g7fe99a @ > /home/usuario/org-mode/maint/lisp/) >=20 >=20 > TIA. > Miguel Ruiz.