comp.lang.ada
 help / color / mirror / Atom feed
From: Nick Roberts <nick.roberts@acm.org>
Subject: Re: Ada begginer's new problem.
Date: Thu, 28 Oct 2004 21:19:18 +0100
Date: 2004-10-28T21:19:18+01:00	[thread overview]
Message-ID: <2ud2i7F29ahnhU1@uni-berlin.de> (raw)
In-Reply-To: <clqa5t$pif$1@netnews.hinet.net>

bubble wrote:

>    outer:loop
>          execute_some_Statement_here0;
>       EXIT when some_condition;
>          execute_some_Statement_here1;
>       inner: loop
>          execute_some_Statement_here3;
>          IF some_condition_is_true THEN
>             goto outerContinueLabel;
>          END IF;
>          execute_some_Statement_here4;
>       end loop inner;
>          execute_some_Statement_here5;
>       <<outerContinueLabel>>
>          null;
>    end loop outer;
> 
> It's hard to read,
> How should I do to remove "goto"  ....?

In the above construction, it appears execute_some_Statement_here5 can
never be executed. Did you make a mistake?
         
Anyway, my personal advice would be not to try to eliminate gotos that
are difficult to eliminate. I think it is nearly always better (clearer,
easier to understand) to leave them in.

> I know there are some choices can apply to my program.
> ( a ). Type stock_price is new float;
> ( b ). Type stock_price is digits 5;
> ( c ). Subtype stock_price is float;
> ...
> if we don't consider ( c ) style, only  consider (a) and (b).
> which style is best?

I suggest you use a decimal fixed-point type for a stock price. It has
absolute accuracy. For example:

   type Stock_Price_in_Dollars is
      delta 0.01 digits 10 range 0.00 .. 99_999_999.99;

This requests a type which is always accurate to the cent, and can
represent values up to (but not including) $100mil.

It is usually better to declare types with an explicit request of the
properties you require of them. It may be possible for a pre-existing
type to not have these properties.

I think it is possible that you might want a more general-purpose type
to do all your currency calculations, and to use subtypes to impose
appropriate ranges. For example:

   type Dollars is delta 0.01 digits 10;

   subtype Stock_Price_in_Dollars is
      Dollars range 0.00 .. 99_999_999.99;

   subtype Price_Differential_in_Dollars is
      Dollars range -99_999_999.99 .. 99_999_999.99;

This way, you do not have the (probably inapproprate) inconvenience of
doing a lot of conversions to do mixed arithmetic:

   Old_Price, New_Price: Stock_Price_in_Dollars;
   Price_Change: Price_Differential_in_Dollars;
   ...
   New_Price := Old_Price + Price_Change;

> 3. possible assign a IEEE754 NaN value to float type variable?

It is implementation defined how to do this sort of thing. If you look
in the reference manual for your Ada compiler, you may find that there
is a method (for example, an implementation-defined attribute).

-- 
HTH
Nick Roberts



  parent reply	other threads:[~2004-10-28 20:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-28  8:11 Ada begginer's new problem bubble
2004-10-28  8:44 ` Jacob Sparre Andersen
2004-10-28 10:38 ` Larry Kilgallen
2004-10-28 11:26 ` Eric Jacoboni
2004-10-28 20:19 ` Nick Roberts [this message]
2004-10-29  2:58   ` bubble
2004-10-29  2:47 ` Steve
replies disabled

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