[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] float format specifier in ob-C.el
From: |
Leo Butler |
Subject: |
Re: [PATCH] float format specifier in ob-C.el |
Date: |
Thu, 1 Jun 2023 19:00:49 +0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) |
On Thu, Jun 01 2023, Ihor Radchenko <yantar92@posteo.net> wrote:
> 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.
Done.
>
>> --- 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.
Ok, I have made the changes requested. Please see the attached patch.
Leo
0001-lisp-ob-C.el-replace-f-with-s-to-prevent-unneeded-ro.patch
Description: 0001-lisp-ob-C.el-replace-f-with-s-to-prevent-unneeded-ro.patch