comp.lang.ada
 help / color / mirror / Atom feed
* Math on dimensioned quantities
@ 1996-07-09  0:00 W. Wesley Groleau (Wes)
  1996-07-09  0:00 ` progers
  1996-07-10  0:00 ` Robert A Duff
  0 siblings, 2 replies; 8+ messages in thread
From: W. Wesley Groleau (Wes) @ 1996-07-09  0:00 UTC (permalink / raw)



I once had to design and code capabilities for numeric types with
dimensions.  Did it two ways: for support code, each number was a record
with its value and the units (enumerated).  Efficiency was not a problem,
but the lack of the 'usual' attributes was an irritation.

The deliverable code used derived floats, not for the sake of attributes,
but because of the (unfounded?) fear of size and time degradation.  What
turned out to be a nuisance here was redefining all the operators.
A generic "operator with conversion factor" was easy enough though
tedious for the legal operations such as
   "+"(L:feet;R:inch)return inch -> inch(L)*12+R
Had to instantiate it in the spec in Ada-83, but now it can be
instantiated in the body and then renamed.

But it was a nuisance to have to declare Units_Mismatch : exception
and redefine MANY multipliers and dividers to raise it.  [For example
"*"(L,R:inch)return inch]

Some compilers will warn you "xxx exception will be raised at run-time"
but it would be a nice language "feature" to extend type checking to
this.  I realize that for a compiler to know all the options, it would
also have to know all the units, which is not feasible.  But--compiler
writers listening?--how about a pragma similar to

   pragma Disallow ( Operation => "*", For_Type => Inch );

If I'm repeating anyone (I don't get "Ada Letters") please forgive me.


---------------------------------------------------------------------------
W. Wesley Groleau (Wes)                                Office: 219-429-4923
Magnavox - Mail Stop 10-40                               Home: 219-471-7206
Fort Wayne,  IN   46808              elm (Unix): wwgrol@pseserv3.fw.hac.com
---------------------------------------------------------------------------




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

end of thread, other threads:[~1996-07-11  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-07-09  0:00 Math on dimensioned quantities W. Wesley Groleau (Wes)
1996-07-09  0:00 ` progers
1996-07-10  0:00 ` Robert A Duff
1996-07-10  0:00   ` progers
1996-07-10  0:00   ` Jon S Anthony
1996-07-10  0:00     ` Robert A Duff
1996-07-10  0:00       ` Robert Dewar
1996-07-11  0:00         ` Dale Stanbrough

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