Delftware Scientific Extension to JAVA
Delftware Technology 1996 proposes extensions to JAVA in terms of scientific units and dimensions
Computing in scientific and engineering areas greatly deals with manipulating numbers that represent physical dimensions, such as duration, weight, and force. A common source of errors is mangling with numbers that represent different kinds of dimensions, or that are related to different units of measurement.
There have been several attempts to add support for handling units of measurement to programming languages. The goal was to ease programming and to make it less error prone. The results were appearently not good enough, since we don't see them.
These pages present a simple proposal for supporting units of measurement in the new programming language Java. Java is a steadily growing language in the Internet community; its application in scientific and engineering environments is not yet in the spotlight, since performance is still lagging behind other languages (Fortran, C, C++, Pascal) by an order of magnitude. This situation is about to improve withing the next few years. Java's excellent power-complexity ratio gives it the potential to rank soon as language number one in scientific and engineering areas.
The proposed language extension involves one new keywords (dimension), and an extension to the syntax of arithmetic types. It prevents mangling different kinds of physical entities, and it takes care of unit conversion. Conversion from and to scalar (plain arithmetic) values is only possible by specifying applicable units.
The extension mainly performs dimension checking at compile time; its only run-time involvement deals with unit conversion, as far as non-basic units are used.
The proposal consists of 4 categories of language extensions, and one keyword.
Some dimensions are more basic than others. There are 7 base dimensions for physics defined in the International System of Units (SI):
amount of substance
For each of these dimensions we can define a primary unit:
The dimension ...(...) construct specifies these base dimensions:
dimension Length (meter );
dimension Mass (kilogram);
dimension Time (second );
dimension ElectricCurrent (Ampere );
dimension Temperature (Kelvin );
dimension AmountOfSubstance (mol );
dimension LuminousIntensity (Candela );
These declarations occur as member declarations inside a class or interface.
Internal machine representations of dimensioned variables are relative to the base units.
Multiplication and division of the base dimensions will yield other dimensions:, e.g.,
speed equals length divided by time
acceleration equals speed divided by time
impulse equals mass times speed
force equals mass times acceleration
The dimension...=... construct covers these derived dimensions:
dimension Speed = Length / Time;
dimension Acceleration = Length / Time;
dimension Impulse = Mass * Speed;
dimension Force = Mass * Acceleration;
"1" can also occur as a dimension on the right-hand side in this construct, as in:
dimension Frequency = 1 / Time;
Units are variables of dimension types . The ones that are not defined with the base dimensions, are derived. This proposal lists 2 options for defined units. They may be regarded as normal variables, most often final:
final double* Mass gram = kilogram / 1000.0;
final int * Length kilometer = 1000 * meter;
This would cause a gram always to be represented as a double. One may also opt for float precision.
The actual usage of units of measurement is in dimensioned numbers. These have a type made up of a arithmetic type (int, float, ...) and a dimension. Actual values are made up of a combination of arithmetic values (0, 1, 0.1, ...) and units. Like with dimensions and units, multiplication and division on dimensioned numbers yield dimensioned numbers of possibly different dimensions:
double * Time t;
float * Length l = 60 * meter;
t = 18.3; // compile error
t = 18.3 * second;
System.out.println ("speed: " + (l/t)); // compile error
System.out.println ("speed: "
+ ( (l/t) / (kilometer/hour))
+ " kilometer/hour");
double * ElectricPotential potential = 3.5 * Volt;
double * ElectricResistance resistance = 1200 * Ohm;
System.out.println ("Electric current: "
+ ( (potential/resistance)
External link: onlne copy