emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/org dd12e9c763 2/4: ob-calc.el: Fix assigning floating


From: ELPA Syncer
Subject: [elpa] externals/org dd12e9c763 2/4: ob-calc.el: Fix assigning floating point numbers
Date: Thu, 2 May 2024 09:58:33 -0400 (EDT)

branch: externals/org
commit dd12e9c763097c8b06295330544246b49c9bd39d
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>

    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
---
 lisp/ob-calc.el              | 26 +++++++++++++++-----------
 testing/lisp/test-ob-calc.el |  8 ++++++++
 2 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/lisp/ob-calc.el b/lisp/ob-calc.el
index 810ed1735c..f6d3642386 100644
--- a/lisp/ob-calc.el
+++ b/lisp/ob-calc.el
@@ -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
diff --git a/testing/lisp/test-ob-calc.el b/testing/lisp/test-ob-calc.el
index 6d6ca104d4..bfe41eb3ae 100644
--- a/testing/lisp/test-ob-calc.el
+++ b/testing/lisp/test-ob-calc.el
@@ -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 "\



reply via email to

[Prev in Thread] Current Thread [Next in Thread]