comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: no + or - defined for fixed point types in Standard, why ?
Date: Wed, 24 Jan 2018 21:25:52 -0600
Date: 2018-01-24T21:25:52-06:00	[thread overview]
Message-ID: <p4bio0$s3b$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: 3d796e5f-015e-469c-bbcb-edc3303793ab@googlegroups.com

"+" and "-" (and many other operators, as well, look in Chapter 4 of the Ada 
Standard) are declared at the point of the type declaration, not in package 
Standard. So if you need to use direct notation for the ones in this 
program, you have to prefix by the package name that contains the operators 
(which you didn't provide because you didn't provide a compilable example 
yet again), not Standard.

Ignore the goofy "*" and "/" for fixed point types in Standard, they have a 
specialized use. The usual operators are declared with the type, just like 
with integer and float types. Most of the operators in Standard are for use 
with the predefined types, which a type with an explicit declaration like 
Modele is not.

Derived types get a copy of the operators of the parent type, also declared 
at the point of the type. So the same is true for T_Proba.

                        Randy.


"Mehdi Saada" <00120260a@gmail.com> wrote in message 
news:3d796e5f-015e-469c-bbcb-edc3303793ab@googlegroups.com...
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.
I got that:
p_proba1.adb:11:37: warning: instance does not use primitive operation "+" 
at p_proba1.ads:8
p_proba1.adb:11:37: warning: instance does not use primitive operation "*" 
at p_proba1.ads:12
p_proba1.adb:11:37: warning: instance does not use primitive operation "-" 
at p_proba1.ads:16
p_proba1.adb:43:16: "-" not declared in "Standard"

I could see that + and - weren't defined for universal_fixed in Standard, 
though they are indeed, hum, defined in real life. What does it mean ?

Here's my type definitions:

   type T_proba is private;
private
   type Modele is delta 0.001 range 0.0..1.0 with Small => 0.001; -- to 
style have at hands primitives for fixed point types.
   type T_proba is new MODELE; -- what I know I should use (but it still say 
"instance blablabla"

And in the body, to define the operation, I convert to Modele.
But I got those warnings:
p_proba1.adb:11:37: warning: instance does not use primitive operation "+" 
at p_proba1.ads:8
p_proba1.adb:11:37: warning: instance does not use primitive operation "*" 
at p_proba1.ads:12
p_proba1.adb:11:37: warning: instance does not use primitive operation "-" 
at p_proba1.ads:16

Is there another way to refer to the T_proba's primitive operations ? And 
why does it upset the compiler ?
I try to add "overriding" to these three operations, since I read it was a 
good practice, and I only got one more error: "subprogram "*" is not 
overriding"...

I just read the course's parts on numerics, and I admit I didn't get most of 
it, by far. Was much much harder to me, than Ada proper. But I don't 
remember, and can't find info on any of these points...


My operators' definitions:
   function "*"
     (Un,
         Deux : in     T_Proba)
      return T_Proba is (Standard."*"(Un, Deux));
   function "+"
     (Un,
         Deux : in     T_Proba)
        return T_Proba is ((-Un) * (-Deux));
   function "-"
     (Un : in     T_Proba)
      return T_Proba
   is (Standard."-"(1.0 - UN));

ps: remember, I KNOW it's wrong. but I wonder why exactly. 



  parent reply	other threads:[~2018-01-25  3:25 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
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 [this message]
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