Physics::Unit::Implementation - This page discusses implementation issues of the Physics/Unit.pm module.
Each unit is defined by a conversion factor and a dimensionality vector.
The conversion factor is a floating point number that specifies how this Unit relates to a reference Unit of the same dimensionality.
The dimensionality vector holds a list of integers - each of which records the power of a base Unit that appears in this Unit.
For example, consider the unit of speed, "miles per hour". This has a dimensionality of (Distance / Time), or of (Distance ^ 1 * Time ^ -1). So this unit's dimensionality vector has a 1 in the place corresponding to Distance, and a -1 in the place corresponding to Time.
The reference unit for speed is "meters per second" (since meter is the base unit corresponding to Distance, and second is the base unit corresponding to Time). Therefore, the conversion factor for the unit "miles per hour" is 0.44704, since 1 mph equals 0.44704 meters / sec.
Turning this on enables copious debugging information.
A (correct) regular expression for a floating point number, optionally in exponent form.
A list of reserved words used in unit expressions. For example, "per", "square", "cubic".
The keys of this hash are the known unit names. The values are references to the named unit objects.
Keys are the valid prefixes.
Values are references to the Unit objects.
Note that the names here are also in
Keys are the names of the types. The values of this hash are references to Unit objects that exemplify these types.
The number of base units.
The name of each of the base units.
These names also appear in
Creates a new dimensionless unit.
This is called during the object's construction to add a list of names to the 'names' array,
and to set the reference in the
%unit_by_names cross-reference hash.
This is called when we are adding a new type to the system.
This happens both in
InitBaseUnits() and in
This is used by several of the interface utility functions to create a new unit object from a unit definition (either a simple name, a unit expression, or a unit object).
It differs from
GetUnit() in that it always creates a new,
if given a simple name,
returns a reference to a named Unit.
Compare the dimension arrays. Return 0 if they are the same.
Look up the name. Returns:
0 not defined 1 reserved word 2 unit name 3 type name
Convert the unit to a factor - dimension vector format string, e.g. the unit '3 meters' would be converted to something like
3 [1, 0, 0]
Complain if this unit has a name. This is used by all the methods that modify the value of the unit.