emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Leo Butler <Leo.Butler@umanitoba.ca>
Cc: Org Mode Mailing List <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] float format specifier in ob-C.el
Date: Thu, 01 Jun 2023 08:27:33 +0000	[thread overview]
Message-ID: <87leh3bn9m.fsf@localhost> (raw)
In-Reply-To: <87pm6g4ina.fsf@t14.reltub.ca>

Leo Butler <Leo.Butler@umanitoba.ca> writes:

> In ob-C.el, line 339 has the format specifier
>
> 	    (`floatp '("double" "%f"))
>
> to print literal floats. However, that format specifier rounds, which
> can result in errors. I think the correct approach is to print the
> float without rounding or padding or trying to guess at the desired
> accuracy (and let the compiler do whatever is needed):
>
>            (`floatp '("double" "%s"))

Makes sense. Thanks!

> -	    (`floatp '("double" "%f"))
> +	    (`floatp '("double" "%s"))

Please add comment explaining why not %f. Otherwise, it is not fully
clear why "%s" is used.

> --- a/testing/examples/ob-C-test.org
> +++ b/testing/examples/ob-C-test.org
> @@ -60,6 +60,12 @@
>    return 0;
>  #+end_src
>  
> +#+source: float_var
> +#+begin_src cpp :var x=1.123456789012345678 :includes "<iostream>" :results silent
> +double y = 1.123456789012345678;
> +std::cout << (x == y);
> +#+end_src

Please move the source block directly into the test using
`org-test-with-temp-text'. The test will be more readable then.

`org-test-at-id' should better be used only when necessary in order to
not jump back and forth when debugging tests.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


  reply	other threads:[~2023-06-01  8:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-31 15:36 [PATCH] float format specifier in ob-C.el Leo Butler
2023-06-01  8:27 ` Ihor Radchenko [this message]
2023-06-01 19:00   ` Leo Butler
2023-06-02  7:25     ` Ihor Radchenko
2023-06-02 13:50       ` Leo Butler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87leh3bn9m.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=Leo.Butler@umanitoba.ca \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).