<div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace;font-size:large">Thanks, it works for me!</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:large"><br></div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><font face="monospace, monospace" size="4">Po-Hsun Tseng (Rocky)</font></div></div></div></div></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Feb 10, 2020 at 7:00 PM <<a href="mailto:cln-list-request@ginac.de">cln-list-request@ginac.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Send CLN-list mailing list submissions to<br>
<a href="mailto:cln-list@ginac.de" target="_blank">cln-list@ginac.de</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
<a href="https://www.ginac.de/mailman/listinfo/cln-list" rel="noreferrer" target="_blank">https://www.ginac.de/mailman/listinfo/cln-list</a><br>
or, via email, send a message with subject or body 'help' to<br>
<a href="mailto:cln-list-request@ginac.de" target="_blank">cln-list-request@ginac.de</a><br>
<br>
You can reach the person managing the list at<br>
<a href="mailto:cln-list-owner@ginac.de" target="_blank">cln-list-owner@ginac.de</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of CLN-list digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
1. Re: adding two different precision number (Po-Hsun Tseng)<br>
2. print multi-precision floating number in scientific notation<br>
(Po-Hsun Tseng)<br>
3. Re: print multi-precision floating number in scientific<br>
notation (Richard B. Kreckel)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Sun, 9 Feb 2020 21:35:30 +0800<br>
From: Po-Hsun Tseng <<a href="mailto:zengbs@gmail.com" target="_blank">zengbs@gmail.com</a>><br>
To: Bruno Haible <<a href="mailto:bruno@clisp.org" target="_blank">bruno@clisp.org</a>><br>
Cc: <a href="mailto:cln-list@ginac.de" target="_blank">cln-list@ginac.de</a><br>
Subject: Re: [CLN-list] adding two different precision number<br>
Message-ID:<br>
<<a href="mailto:CA%2BHRcQvs_sxgtgZU7z4qR_1shrhTo2YWmNPfee2Lx9gDpdQkPg@mail.gmail.com" target="_blank">CA+HRcQvs_sxgtgZU7z4qR_1shrhTo2YWmNPfee2Lx9gDpdQkPg@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
Dear Bruno,<br>
<br>
Thank you for your quick and detailed reply.<br>
<br>
Po-Hsun Tseng (Rocky)<br>
<br>
<br>
On Sun, Feb 9, 2020 at 6:37 PM Bruno Haible <<a href="mailto:bruno@clisp.org" target="_blank">bruno@clisp.org</a>> wrote:<br>
<br>
> Hi,<br>
><br>
> > 1. Does CLN support performing two different precision number with basic<br>
> > overloading operators (+,-,*, and /)?<br>
><br>
> Yes.<br>
><br>
> > 2. If yes, how does CLN treat that? eg. zero padding on the<br>
> precision-less<br>
> > number before doing operation?<br>
><br>
> It does zero-padding on the operand with the smaller precision, then the<br>
> operation on the then equal-size operands, and finally rounding<br>
> (round-to-even)<br>
> to the smallest precision among the operands.<br>
><br>
> Example (using decimal numbers for illustrative purposes):<br>
><br>
> 3.14149265358979323<br>
> + 2.718282<br>
> ---------------------<br>
> 3.14149265358979323<br>
> + 2.71828200000000000<br>
> ---------------------<br>
> 5.85969465358979323<br>
> ---------------------<br>
> 5.859695<br>
><br>
> Therefore, when some computation returns a result, usually a few decimal<br>
> places at the end can be wrong, but CLN will never give you a 50-digit<br>
> result when in fact the accurary is only 10 digits - UNLESS you use<br>
> conversion functions [1] explicitly.<br>
><br>
> Bruno<br>
><br>
> [1] <a href="https://www.ginac.de/CLN/cln.html#Conversion-functions" rel="noreferrer" target="_blank">https://www.ginac.de/CLN/cln.html#Conversion-functions</a><br>
><br>
><br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://www.ginac.de/pipermail/cln-list/attachments/20200209/684f0626/attachment-0001.htm" rel="noreferrer" target="_blank">http://www.ginac.de/pipermail/cln-list/attachments/20200209/684f0626/attachment-0001.htm</a>><br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Mon, 10 Feb 2020 12:38:44 +0800<br>
From: Po-Hsun Tseng <<a href="mailto:zengbs@gmail.com" target="_blank">zengbs@gmail.com</a>><br>
To: <a href="mailto:cln-list@ginac.de" target="_blank">cln-list@ginac.de</a><br>
Subject: [CLN-list] print multi-precision floating number in<br>
scientific notation<br>
Message-ID:<br>
<CA+HRcQuDUsm_F54LNyHnJMaffYZuAFJQTWiCKVN_YXt=<a href="mailto:RgV3ig@mail.gmail.com" target="_blank">RgV3ig@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
Hi CLN developers,<br>
<br>
Sorry for frequently asking questions. I have checked manual and searched<br>
mailing list for full example, but nothing inside. Moreover, I only<br>
familiar with C...<br>
Question: How to use `print_float()` to print multi-precision floating<br>
number in scientific notation on terminal? below is the full code I have<br>
ever tried, but it always gives me compilation error.<br>
thanks.<br>
<br>
#include <cln/io.h><br>
#include <cln/float.h><br>
#include <cln/float_io.h><br>
<br>
<br>
using namespace cln;<br>
<br>
int main( ) {<br>
<br>
int N = 10;<br>
<br>
cl_F x[N];<br>
<br>
for (int i=0 ;i<N;i++) x[i] =<br>
"0.333333333333333333333333333333333333333333333333333333333333";<br>
<br>
// cl_print_flags.float_readably = true;<br>
<br>
for (int i=0 ;i<N;i++) print_float(stdout,<br>
cl_print_flags.float_readably, x[i]);<br>
<br>
return 0 ;<br>
}<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://www.ginac.de/pipermail/cln-list/attachments/20200210/b08094e2/attachment-0001.htm" rel="noreferrer" target="_blank">http://www.ginac.de/pipermail/cln-list/attachments/20200210/b08094e2/attachment-0001.htm</a>><br>
<br>
------------------------------<br>
<br>
Message: 3<br>
Date: Mon, 10 Feb 2020 10:23:06 +0100<br>
From: "Richard B. Kreckel" <<a href="mailto:kreckel@in.terlu.de" target="_blank">kreckel@in.terlu.de</a>><br>
To: <a href="mailto:cln-list@ginac.de" target="_blank">cln-list@ginac.de</a><br>
Subject: Re: [CLN-list] print multi-precision floating number in<br>
scientific notation<br>
Message-ID: <<a href="mailto:937a1dc6-ab90-c80c-932e-691b864a2f03@in.terlu.de" target="_blank">937a1dc6-ab90-c80c-932e-691b864a2f03@in.terlu.de</a>><br>
Content-Type: text/plain; charset=utf-8<br>
<br>
Hi,<br>
<br>
You should first create the desired cl_print_flags object and then pass<br>
it as reference to the print_float function, like this:<br>
cl_print_flags flags;<br>
flags.float_readably = true;<br>
print_float(std::cout, flags, x[i]);<br>
<br>
Note also that stdout is not a C++ stream. I've replaced it with cout.<br>
<br>
-richy.<br>
-- <br>
Richard B. Kreckel<br>
<<a href="https://in.terlu.de/~kreckel/" rel="noreferrer" target="_blank">https://in.terlu.de/~kreckel/</a>><br>
<br>
On 10.02.20 05:38, Po-Hsun Tseng wrote:<br>
> #include <cln/io.h><br>
> #include <cln/float.h><br>
> #include <cln/float_io.h><br>
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?<br>
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?<br>
> using namespace cln;<br>
> ?<br>
> int main( ) {<br>
> <br>
> ? ? int N = 10;<br>
> ?<br>
> ? ? cl_F x[N];<br>
> ?<br>
> ? ? for (int i=0 ;i<N;i++) x[i] =<br>
> "0.333333333333333333333333333333333333333333333333333333333333";<br>
> ? ?<br>
> // ? ?cl_print_flags.float_readably = true;<br>
> ?<br>
> ? ? for (int i=0 ;i<N;i++)?print_float(stdout,<br>
> cl_print_flags.float_readably, x[i]);<br>
> ??<br>
> ? ? return 0 ;<br>
> }<br>
<br>
<br>
------------------------------<br>
<br>
Subject: Digest Footer<br>
<br>
_______________________________________________<br>
CLN-list mailing list<br>
<a href="mailto:CLN-list@ginac.de" target="_blank">CLN-list@ginac.de</a><br>
<a href="https://www.ginac.de/mailman/listinfo/cln-list" rel="noreferrer" target="_blank">https://www.ginac.de/mailman/listinfo/cln-list</a><br>
<br>
<br>
------------------------------<br>
<br>
End of CLN-list Digest, Vol 91, Issue 2<br>
***************************************<br>
</blockquote></div>