[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org d55a112149 2/4: lisp/ob-C.el: replace %f with %s to
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org d55a112149 2/4: lisp/ob-C.el: replace %f with %s to prevent unneeded rounding |
Date: |
Fri, 2 Jun 2023 03:59:27 -0400 (EDT) |
branch: externals/org
commit d55a1121490334851b7eb7ba184e01b361a8ab75
Author: Leo Butler <leo.butler@umanitoba.ca>
Commit: Ihor Radchenko <yantar92@posteo.net>
lisp/ob-C.el: replace %f with %s to prevent unneeded rounding
* lisp/ob-C.el (org-babel-C-val-to-C-type): Floats should be printed
as string literals to prevent rounding introduced by %f format.
* testing/lisp/test-ob-C.el (ob-C/float-var): Test that floats are not
rounded when passed as an org :var.
---
lisp/ob-C.el | 2 +-
testing/lisp/test-ob-C.el | 11 +++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/lisp/ob-C.el b/lisp/ob-C.el
index 3a6e99623f..7763c4c07c 100644
--- a/lisp/ob-C.el
+++ b/lisp/ob-C.el
@@ -339,7 +339,7 @@ FORMAT can be either a format string or a function which is
called with VAL."
(type
(pcase basetype
(`integerp '("int" "%d"))
- (`floatp '("double" "%f"))
+ (`floatp '("double" "%s")) ;; %f rounds, use %s to print the float
literally
(`stringp
(list
(if (eq org-babel-c-variant 'd) "string" "const char*")
diff --git a/testing/lisp/test-ob-C.el b/testing/lisp/test-ob-C.el
index b6dbed8e31..8546a48dda 100644
--- a/testing/lisp/test-ob-C.el
+++ b/testing/lisp/test-ob-C.el
@@ -95,6 +95,17 @@
(org-babel-next-src-block 10)
(should (= 42 (org-babel-execute-src-block))))))
+(ert-deftest ob-C/float-var ()
+ "Test that floats are passed without unnecessary rounding."
+ (if (executable-find org-babel-C++-compiler)
+ (org-test-with-temp-text
+"#+source: float_var
+#+begin_src cpp :var x=1.123456789012345678 :includes \"<iostream>\" :results
silent
+double y = 1.123456789012345678;
+std::cout << (x == y);
+#+end_src"
+(should (= 1 (org-babel-execute-src-block))))))
+
(ert-deftest ob-C/table ()
"Test of a table output"
(if (executable-find org-babel-C++-compiler)