comp.lang.ada
 help / color / mirror / Atom feed
* SI Units Checked and Unchecked
@ 2018-08-09 12:44 AdaMagica
  2018-08-09 13:47 ` Dan'l Miller
                   ` (2 more replies)
  0 siblings, 3 replies; 32+ messages in thread
From: AdaMagica @ 2018-08-09 12:44 UTC (permalink / raw)


This is a complete rework using Ada 2012 predicates.

These packages provide a method to commpute with physical items in full generality under dimensional correctness checking. Dimensioned items are written in a natural style with the unit attached as a string.

The base type is private:

  type Item is private;

There are subtypes defined for all 7 base units defined in the SI system and many more:

  subtype Length is Item with Dynamic_Predicate => has_Dimension (Length, "m");
  subtype Volume is Item with Dynamic_Predicate => has_Dimension (Volume, "m**3");
  subtype Speed  is Item with Dynamic_Predicate => has_Dimension (Speed , "m/s");
  subtype Force  is Item with Dynamic_Predicate => has_Dimension (Force , "N");
  subtype Resistance is Item with Dynamic_Predicate => has_Dimension (Resistance, "Ohm");

Variables are defined like this:

  A: Acceleration := 5.0*"m/s**2";
  V: Speed := 10.0*"km/h";
  T: Time  :=  1.0*"min";
  D: Length := V*T + 0.5*A*T**2;

  D := 1.0*"J";  will raise an exception.

Units and prefixes are case sensitive (as defined in SI): "mS" is millisiemens, "Ms" is megasecond.

Dimensioned IO is also provided:

  V := 1.0*"m/s";          -- output as
  Put (V);                 -- 1.0*m*s**(-1)
  Put (V, Dim => "km/h");  -- 3.6*km/h
  Put (V, Dim => "s");     -- will raise an exception

Download from here:
http://www.christ-usch-grein.homepage.t-online.de/Ada/Dimension/SI.html

If you should use (even like) this method, please drop me a note with your findings.

Have fun.
Christoph

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

end of thread, other threads:[~2020-08-13 12:24 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-09 12:44 SI Units Checked and Unchecked AdaMagica
2018-08-09 13:47 ` Dan'l Miller
2018-08-09 14:07   ` Dmitry A. Kazakov
2018-08-09 15:03     ` Dan'l Miller
2018-08-09 15:51       ` Dmitry A. Kazakov
2018-08-09 17:32         ` Dan'l Miller
2018-08-09 19:42           ` Dmitry A. Kazakov
2018-08-09 22:12             ` Dan'l Miller
2018-08-10  6:45               ` Dmitry A. Kazakov
2018-08-10 13:59                 ` Dan'l Miller
2018-08-10 14:50                   ` Dmitry A. Kazakov
2018-08-10 17:04                     ` Dan'l Miller
2018-08-10 17:34                       ` Dmitry A. Kazakov
2018-08-11  4:42                         ` Paul Rubin
2018-08-11  5:46                           ` Dmitry A. Kazakov
2018-08-11 19:57                             ` Paul Rubin
2018-08-11 21:01                               ` Dmitry A. Kazakov
2018-08-09 18:47       ` Paul Rubin
2018-08-09 19:13         ` Dan'l Miller
2018-08-09 14:31   ` AdaMagica
2018-08-09 15:19     ` Dan'l Miller
2018-08-09 16:07 ` Jeffrey R. Carter
2018-08-09 17:41   ` AdaMagica
2018-08-09 20:34     ` Jeffrey R. Carter
2018-08-10  9:13       ` AdaMagica
2018-08-10 20:20         ` Jeffrey R. Carter
2018-08-13  8:57           ` AdaMagica
2018-08-20 17:55             ` AdaMagica
2019-09-04 14:20 ` Shark8
2019-09-04 17:11   ` AdaMagica
2019-09-06 21:01     ` Shark8
2020-08-13 12:24       ` SI Units Checked and Unchecked - Completela overhauled version AdaMagica

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