Another library for type checking of dimensioned quantities at compile time in FreePascal. From a circular's idea.
Ensuring coherence of physical dimensions in physical equations or mathematical relationships involving various variables is crucial. Dimensional analysis provides a fundamental tool to verify this coherence and correct any errors in the expressions.
The ADim library allows defining variables and constants in terms of quantity and units of measurement, automating dimensional analysis at compilation time.
uses
ADim;
var
distance: TMeters;
time: TSeconds;
speed: TMetersPerSecond;
begin
distance := 5000*m;
time := 2*hr;
speed := distance/time;
writeln('The value of speed is ', speed.ToKilometerPerHour.ToString);
end;
Output:
The value of speed is 2.5 km/h
uses
ADim;
var
plank: TJouleSeconds;
e0: TFaradsPerMeter;
ke: TNewtonSquareMetersPerSquareCoulomb;
mass: TKilograms;
charge: TCoulombs;
radius: TMeters;
begin
plank := 6.62607015E-34*J*s; // Planck constant
e0 := 8.8541878128E-12*F/m; // vacuum permittivity
ke := 1/(4*pi*e0); // Coulomb constant
mass := 9.1093837015E-31*kg; // mass of an electron
charge := 1.602176634E-19*C; // charge of an electron
radius := (SquarePower(plank/2/pi)/mass)/(ke*SquarePower(charge));
writeln('The value of the Bohr radius is ', radius.ToString(10, 10, [pNano]));
end;
Output:
The value of the Bohr radius is 0.05291772109 nm
Refer to the adimtest source code for additional examples.
- Mechanics
- Fluid Mechanics
- Electricity and Magnetism
- Heat and Thermodynamics
- Waves and Hearing
- Light and Vision
- Relativity
- Quantum Mechanics
- Units of measurement