Dear CLN developers, 1. Does CLN support performing two different precision number with basic overloading operators (+,-,*, and /)? 2. If yes, how does CLN treat that? eg. zero padding on the precision-less number before doing operation? 3. If no, how can i achieve that? thanks. Po-Hsun Tseng (Rocky)
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
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
participants (2)
-
Bruno Haible
-
Po-Hsun Tseng