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