comp.lang.ada
 help / color / mirror / Atom feed
From: yogeshwarsing@gmx.com
Cc: nma@12000.org
Subject: Re: GNAT and Dimension Checking
Date: Sun, 1 Jul 2012 03:44:19 -0700 (PDT)
Date: 2012-07-01T03:44:19-07:00	[thread overview]
Message-ID: <3c38572a-c06c-4b58-9405-ece43483b3cd@googlegroups.com> (raw)
In-Reply-To: <jsoqgi$s4v$1@speranza.aioe.org>

This feature is rather limited though. For example one cannot do conversions. If you have to work with an "irregular" unit, you will have to do the conversion yourself e.g.

with System.Dim.MKS; use System.Dim.Mks;
with System.Dim.Mks_IO; use System.Dim.Mks_IO;
with Text_IO; use Text_IO;

procedure Free_Fall3 is
       subtype Acceleration is Mks_Type
       with Dimension => ("m/s^2", Meter => 1, Second => -2, others => 0);
       G : constant acceleration := 127137.6 * km/(hour ** 2) ;
       T : Time := 10.0/3600.0 * hour;
       Distance : length;

     begin
       Put ("Gravitational constant: ");
       Put (G, Aft => 2, Exp => 0); Put_Line ("");
       Put ("Time: ");
       Put (T, fore => 4, Aft => 4, Exp => 0); Put_Line ("");
       Distance := 0.5 * G * T ** 2;
       Put ("distance travelled in 10 seconds (or 10/3600 hour) of free fall ");
       Put (Distance, fore => 4, Aft => 4, Exp => 0);
       Put_Line ("");
end Free_Fall3; 

You will still get the outputs in the default MKS units. So basically, it is just checking if your dimensions are right.


And I do not think that you are able to deal with record constructs such as

 type Motion_Parameter is
       record
         Radius: Length := 0.0 * m;
         Speed : Velocity := 0.0 * m/s;
         Time_Step    : Time :=  0.0 * s;
         Number_Of_Revolutions : Float := 0.0;
       end record;

since Motion_Parameter will need to have a specific dimension in terms of MKS and having different MKS units in the record structure makes this impossible.

YC



  reply	other threads:[~2012-07-01 10:52 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-01  5:53 GNAT and Dimension Checking AdaMagica
2012-07-01  6:25 ` Nasser M. Abbasi
2012-07-01 10:44   ` yogeshwarsing [this message]
2012-07-02 20:42     ` Anh Vo
2012-07-02 20:58       ` Adam Beneschan
2012-07-02 21:51         ` Anh Vo
2012-07-01 15:18 ` AdaMagica
2012-07-01 15:47   ` yogeshwarsing
2012-07-06 10:47 ` AdaMagica
2012-07-08  1:50   ` Robert A Duff
2012-07-08 10:33 ` AdaMagica
2012-07-08 11:37   ` Dmitry A. Kazakov
2012-07-08 14:13     ` AdaMagica
2012-07-08 18:47   ` Jacob Sparre Andersen
2012-07-09 11:06     ` AdaMagica
2012-07-09  8:20   ` Martin
2012-07-09 11:19     ` AdaMagica
replies disabled

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