From: Mehdi Saada <00120260a@gmail.com>
Subject: no + or - defined for fixed point types in Standard, why ?
Date: Wed, 24 Jan 2018 09:03:38 -0800 (PST)
Date: 2018-01-24T09:03:38-08:00 [thread overview]
Message-ID: <3d796e5f-015e-469c-bbcb-edc3303793ab@googlegroups.com> (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.
next reply other threads:[~2018-01-24 17:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-24 17:03 Mehdi Saada [this message]
2018-01-24 17:44 ` no + or - defined for fixed point types in Standard, why ? 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
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox