comp.lang.ada
 help / color / mirror / Atom feed
* How casting works in ada?
@ 2004-11-23 17:26 Abbo
  2004-11-23 19:17 ` Jeffrey Carter
  0 siblings, 1 reply; 2+ messages in thread
From: Abbo @ 2004-11-23 17:26 UTC (permalink / raw)


Hello! SOrry for this very basic question, but I'd like to know what 
happen during a simple casting between types with different size/delta. 
Example:

type one is delta 0.003 range -20.0 .. 200.0;
type two is digits 6 range -10.0 .. 400.0;
type three is delta 0.0023142 range -200.0.. 9999.0;

VAR1 : one := 23.0;
VAR2 : two;
VAR3 : three;

VAR2 := two ( VAR1 );
VAR3 := three (VAR1);

which values are in VAR2 and VAR3 and how ADA calculates it?

Why

VAR2 := two(23.0);

gives different value for VAR2 from

VAR2 := two ( VAR1 );   ??


Thanks in advance!!



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

* Re: How casting works in ada?
  2004-11-23 17:26 How casting works in ada? Abbo
@ 2004-11-23 19:17 ` Jeffrey Carter
  0 siblings, 0 replies; 2+ messages in thread
From: Jeffrey Carter @ 2004-11-23 19:17 UTC (permalink / raw)


Abbo wrote:

> Hello! SOrry for this very basic question, but I'd like to know what 
> happen during a simple casting between types with different size/delta. 

Ada does not have casting. The ARM index entry for "cast" reads

cast
    See type conversion   4.6(1)
    See unchecked type conversion   13.9(1)

AFAICT, this is the only place that "cast" appears in the ARM.

The answer to your question is not simple. See ARM 3.5.9(8) for 
information about how fixed-point types are represented. Loss of 
expected precision in fixed-point types with deltas that are not a power 
of 2 is common.

-- 
Jeff Carter
"We use a large, vibrating egg."
Annie Hall
44




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

end of thread, other threads:[~2004-11-23 19:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-23 17:26 How casting works in ada? Abbo
2004-11-23 19:17 ` Jeffrey Carter

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