[comp.lang.ada] ADA problem, can you help?

oplinger@jupiter.crd.ge.com (B. S. Oplinger) (12/16/89)

	Background:
     I have a problem. It has to do with floating point subtypes and
the 'LARGE attribute. 
     In a program (PIWG to be exact) that I was given, the logic
of a piece of code is:
     A := 2 * INPUT
     if A > the largest value allowed for the type that INPUT is
          stop
     otherwise
          INPUT := A  --  double input
A is a float and INPUT is a subtype whose range is rather much
smaller that the largest float. In practice the code is:
     A := 2.0 * INPUT;
     if A > INPUT_TYPE'LARGE then
          INPUT := 0.0;
     else
          INPUT := A;  --  here is where my problem is
     end if;
When I run this code, it fails at the assignment of A to INPUT.
Through trial and error I found that 10**(-14) * INPUT_TYPE'LARGE
was approximately the largest legal value of INPUT_TYPE allowed. 

Since LRM 3.5.8(9) describes T'LARGE as "Yield the largest
positive model number of the subtype T.", I thought this rather
strange and forwarded it to the compiler manufactured as a
problem. What follows is the answer to my problem. 

---The following is the answer. All/Any typos are my fault.

Original Problem:
     The 'LARGE attribute for floating point values returns the
largest positive model of the subtype defined. When using this
attribute, a warning message is generated by the compiler stating
that a CONSTRAINT_ERROR will be raised at runtime. At runtime,
the CONSTRAINT_ERROR is raised.

Response:
     Customer failed to read the LRM. RM 3.5.7(15) states that
when subtype T is elaborated, "it creates a floating point
subtype whose model numbers are defined by the corresponding
floating accuracy definition". This points out that the model
numbers are based on the "digits" part of the definition, not the
range constraint (i.e., model numbers larger that the range
constraint will be generated). Also, RM 3.5.7(15) goes on to say
that a "value of a floating point type belongs to a floating
point subtype if and only if it belongs to the range defined by
the subtype". Since type'LARGE does not lie in the range defined
by the variable's subtype a constraint_error will be raised.

----End of answer

     I can understand their interpretation of the LRM, but is it the
correct one? In other words, how can I determine, in good ADA
sytle, the largest legal value of a real subtype. 

One answer would be of the form:
  lower_bound : constant float := 0.0;
  upper_bound : constant float := 1_000.0;
  my_float_type is new float digits n range lower_bound to upper_bound;
and then I could use upper_bound instead of 'LARGE.

But, this doesn't help me if I wanted to write a generic
subprogram which had the logic:
    if input > ( ln( input'large ) ) then
       raise exponential_function_error;
    else
       input := exp( input );

Anyone have ideas/comment/suggestions.

As a final note: A different compiler on a different computer
does what I expect. 'LARGE returns the largest value of the
subtype. 

brian
oplinger@crd.ge.com

vestal@SRC.Honeywell.COM (Steve Vestal) (12/16/89)

>In article <4261@crdgw1.crd.ge.com> oplinger@jupiter.crd.ge.com (B. S. Oplinger) writes:
>	A := 2.0 * INPUT;
>	if A > INPUT_TYPE'LARGE then

Try 
        if A > INPUT_TYPE'LAST then