comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Eachus <rieachus@comcast.net>
Subject: Re: no + or - defined for fixed point types in Standard, why ?
Date: Wed, 24 Jan 2018 09:44:59 -0800 (PST)
Date: 2018-01-24T09:44:59-08:00	[thread overview]
Message-ID: <aa3b1466-b4f6-4e83-bac7-17dc88d488a7@googlegroups.com> (raw)
In-Reply-To: <3d796e5f-015e-469c-bbcb-edc3303793ab@googlegroups.com>

On Wednesday, January 24, 2018 at 12:03:40 PM UTC-5, Mehdi Saada wrote:
> I have to define the addition, substraction and multiplication operators for a fixed point real type, and (though I KNOW you don't do, that, but pass use a parent type whose primitives have not been overrided) I tried to prefix by "Standard" to see what happens. I thought it would just not work.

The easy way to "get" Ada fixed point is that it is an integer type with a predefined scaling factor, 'Small.   The predefined operators include +, - multiplication or division by an integer (which returns a value of the type), and  the comparison operators which return Boolean.  Division of two values of the type, returning Integer could also be provided but isn't.

There are special multiplication and division operators which are defined for any two fixed point types, and return a value which must be converted to some type.  Note that division operations are the only ones that can result in rounding.  Obviously this is important when you want to minimize rounding.

As for your problem.the compiler is trying to be nice, and confusing you.  It is hard to correctly override the predefined operators where they are directly visible.  If you can do the overriding where they are use visible that works, except for the magic versions of multiply and divide (that do not have an integer parameter).  To (re-)define * or / you will need to write a body that uses Unchecked_Conversion of the proper integer type, or converts both operands to some floating point type.

As for the warnings?  You are trying to do something wonky, and the compiler is telling you that.  If you really want to do it, consider turning warnings off in the appropriate area.


  reply	other threads:[~2018-01-24 17:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-24 17:03 no + or - defined for fixed point types in Standard, why ? Mehdi Saada
2018-01-24 17:44 ` Robert Eachus [this message]
2018-01-24 18:36   ` Mehdi Saada
2018-01-25  1:09     ` Robert Eachus
2018-01-25  1:31       ` guyclaude.burger
2018-01-25  3:07         ` Robert Eachus
2018-01-25  3:25 ` Randy Brukardt
2018-01-25 13:33   ` Mehdi Saada
2018-01-26  4:34     ` Randy Brukardt
replies disabled

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