ob-calc.el: Fix assigning floating point numbers
* lisp/ob-calc.el (org-babel-execute:calc): Use internal calc format when assigning variable values that are numbers. * testing/lisp/test-ob-calc.el (ob-calc/float-var): New test. Reported-by: Visuwesh <visuweshm@gmail.com> Link: https://orgmode.org/list/87edbu4kdh.fsf@gmail.com
This commit is contained in:
parent
a2e5685e49
commit
dd12e9c763
|
@ -66,17 +66,21 @@
|
|||
(lambda (pair)
|
||||
(let ((val (cdr pair)))
|
||||
(calc-push-list
|
||||
;; For a vector, Calc follows the format (vec 1 2 3 ...) so
|
||||
;; a matrix becomes (vec (vec 1 2 3) (vec 4 5 6) ...). See
|
||||
;; the comments in "Arithmetic routines." section of
|
||||
;; calc.el.
|
||||
(list (if (listp val)
|
||||
(cons 'vec
|
||||
(if (null (cdr val))
|
||||
(car val)
|
||||
(mapcar (lambda (x) (if (listp x) (cons 'vec x) x))
|
||||
val)))
|
||||
val))))
|
||||
(list
|
||||
(cond
|
||||
;; For a vector, Calc follows the format (vec 1 2 3 ...) so
|
||||
;; a matrix becomes (vec (vec 1 2 3) (vec 4 5 6) ...). See
|
||||
;; the comments in "Arithmetic routines." section of
|
||||
;; calc.el.
|
||||
((listp val)
|
||||
(cons 'vec
|
||||
(if (null (cdr val))
|
||||
(car val)
|
||||
(mapcar (lambda (x) (if (listp x) (cons 'vec x) x))
|
||||
val))))
|
||||
((numberp val)
|
||||
(math-read-number (number-to-string val)))
|
||||
(t val)))))
|
||||
(calc-store-into (car pair)))
|
||||
vars)
|
||||
(mapc
|
||||
|
|
|
@ -39,6 +39,14 @@
|
|||
#+END_SRC"
|
||||
(should (equal "27" (org-babel-execute-src-block)))))
|
||||
|
||||
(ert-deftest ob-calc/float-var ()
|
||||
"Test of floating variable."
|
||||
(org-test-with-temp-text "\
|
||||
#+BEGIN_SRC calc :results silent :var x=2.0
|
||||
1/x
|
||||
#+END_SRC"
|
||||
(should (equal "0.5" (org-babel-execute-src-block)))))
|
||||
|
||||
(ert-deftest ob-calc/simple-program-symbolic ()
|
||||
"Test of simple symbolic algebra."
|
||||
(org-test-with-temp-text "\
|
||||
|
|
Loading…
Reference in New Issue