From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!aioe.org!.POSTED.2uCIJahv+a4XEBqttj5Vkw.user.gioia.aioe.org!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Question about best practices with numerical functions Date: Tue, 7 Jul 2020 00:23:06 +0200 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: 2uCIJahv+a4XEBqttj5Vkw.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader01.eternal-september.org comp.lang.ada:59371 List-Id: On 06/07/2020 19:02, Shark8 wrote: > One way to do this would be to use fixed-point types: > (1) Convert your input to the fixed-point that has a "good enough" delta for the precision you want. > (2) Run the algorithm. > (3) Convert back to your normal value-type. > This assumes you're using floating-point or integers, but one nice thing about fixed-point is that it has a bounded error when dealing with operations, unlike floating-point. -- I remember some years ago seeing a bug report dealing with floating-point, where the particular error simply couldn't have happened with fixed-point. Rounding error is bounded in both cases. Fixed-point has same error regardless the values involved in the operations. Floating-point has error depending on the values. I would say that floating-point error would be roughly same for addition, subtraction and multiplication, provided fixed-point does not overflow. It will be hugely better for division. Using fixed-point arithmetic has only sense for a few marginal cases of rounding. Furthermore converting many algorithms to fixed-point might turn quite non-trivial as you will have to ensure absence of overflows and underflows. Where floating-point computation just would lose some precision, fixed-point will catastrophically fail. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de