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!aioe.org!.POSTED.2uCIJahv+a4XEBqttj5Vkw.user.gioia.aioe.org!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Fixed vs float and precision and conversions Date: Wed, 8 Jul 2020 20:36:47 +0200 Organization: Aioe.org NNTP Server Message-ID: References: <756885db-118a-4d76-b90d-e547a3cabf28o@googlegroups.com> <518ff68b-1017-4775-8248-c40048b4fe67o@googlegroups.com> 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: 8bit 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 X-Notice: Filtered by postfilter v. 0.9.2 Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:59401 List-Id: On 08/07/2020 20:10, Björn Lundin wrote: > Den 2020-07-08 kl. 20:08, skrev Björn Lundin: > > The main reason for asking was to see if I got the whole concept > of fixed types wrong or not. Fixed-point is conceptually a scaled integer. You should deal with it accordingly. [It could be a bit surprising in Ada where conversion to integer rounds. In most languages conversion to integer truncates] > I did expect > 'You should do this or that one-liner' as Niklas proposed. > I did not get that to work though What do you mean it does not work? Of course T'Round works for fixed-point types. Simplifying it for positive numbers only T'Round is roughly same as: T (X + T'Small / 2.0) As a side note. Consider the problem of splitting an interval into same-width subintervals. If each subinterval is denoted by its center, you have a problem with the margins of the whole interval as they do not denote any center. Furthermore if zero is included that again poses a question whether it should be in a center of a subinterval (which is then both negative and positive!) or at the margin of two subintervals (and thus not represented as a center!). It is a difficult problem which does not have universal or even intuitive solution. Thus do not expect one-liners. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de