comp.lang.ada
 help / color / mirror / Atom feed
* no + or - defined for fixed point types in Standard, why ?
@ 2018-01-24 17:03 Mehdi Saada
  2018-01-24 17:44 ` Robert Eachus
  2018-01-25  3:25 ` Randy Brukardt
  0 siblings, 2 replies; 9+ messages in thread
From: Mehdi Saada @ 2018-01-24 17:03 UTC (permalink / raw)


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.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-01-26  4:34 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2018-01-25 13:33   ` Mehdi Saada
2018-01-26  4:34     ` Randy Brukardt

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