comp.lang.ada
 help / color / mirror / Atom feed
* Newbie Question: Casting Issue
@ 2004-05-04  9:22 Davide
  2004-05-04 17:40 ` Jeffrey Carter
  2004-05-05 23:07 ` Robert I. Eachus
  0 siblings, 2 replies; 5+ messages in thread
From: Davide @ 2004-05-04  9:22 UTC (permalink / raw)


I need your help, please, to solve a casting issue.

I have an Ada operation, say FLOAT_POINT_OP, which returns a floating point
type, say: FLOAT_POINT_TYPE is digits 9.

The result of this operation must be assigned to a fixed point type
variable, say: FIX_POINT_TYPE is delta 0.0625 range -10.0 .. 36.5.

I cannot use Ada exceptions and I must ensure that the assignment will not
throw a type constraint error at run-time.
Then I perform this check:

FLOAT_VAR >= FLOAT_POINT_TYPE(FIX_POINT_TYPE'FIRST)
and
FLOAT_VAR <= FLOAT_POINT_TYPE(FIX_POINT_TYPE'LAST)

(where FLOAT_VAR is the floating point type result returned by
FLOAT_POINT_OP)

and if the check passes then I perform the "crucial" assignment:

FIX_VAR := FLOAT_VAR.

Do you think it works fine?

Have you better solutions?

My worry is about the FLOAT_POINT_TYPE(FIX_POINT_TYPE'FIRST) casting. In
particular about the possibility of an introduction of additional decimal
digits, after the last decimal digit of the FIX_POINT_TYPE bounds. I think
that everything should work if the casting preserves at least the number of
decimal digits specified for delta (in this case 4 digits, being delta =
0.0625) adding possible digits after the fourth. There is some Ada standard
directive about that?

Thank you.





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

end of thread, other threads:[~2004-05-07  7:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-04  9:22 Newbie Question: Casting Issue Davide
2004-05-04 17:40 ` Jeffrey Carter
2004-05-05 23:07 ` Robert I. Eachus
2004-05-05 23:25   ` Robert I. Eachus
2004-05-07  7:10     ` Davide

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