comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Fixed vs float and precision and conversions
Date: Wed, 8 Jul 2020 20:36:47 +0200	[thread overview]
Message-ID: <re53nq$1gqt$1@gioia.aioe.org> (raw)
In-Reply-To: re526r$mat$2@dont-email.me

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

  parent reply	other threads:[~2020-07-08 18:36 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-07 21:10 Fixed vs float and precision and conversions Björn Lundin
2020-07-07 21:30 ` Niklas Holsti
2020-07-08  8:17   ` Björn Lundin
2020-07-07 21:58 ` Shark8
2020-07-08  8:15   ` Björn Lundin
2020-07-08 16:16     ` Shark8
2020-07-08 18:08       ` Björn Lundin
2020-07-08 18:10         ` Björn Lundin
2020-07-08 18:21           ` Niklas Holsti
2020-07-08 19:39             ` Björn Lundin
2020-07-08 20:34               ` Niklas Holsti
2020-07-08 21:24                 ` Björn Lundin
2020-07-09  7:11                   ` Niklas Holsti
2020-07-08 18:36           ` Dmitry A. Kazakov [this message]
2020-07-08 19:41             ` Björn Lundin
2020-07-09  6:20               ` Dmitry A. Kazakov
2020-07-09  7:23                 ` Björn Lundin
2020-07-09  7:49                   ` Dmitry A. Kazakov
2020-07-08 21:16         ` Shark8
2020-07-08 21:47           ` Björn Lundin
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox