Why are Volts, Amps, and Ohms compatible?
with ada.text_io; use ada.text_io;
procedure main is
type Volts is delta 1.0 / 2.0 ** 12 range -45_000.0 .. 45_000.0;
type Amps is delta 1.0 / 2.0 ** 16 range -1_000.0 .. 1_000.0;
type Ohms is delta 0.125 range 0.0 .. 1.0E8;
V : Volts := 1.0;
A : Amps := 1.0;
R1 : Ohms := 1.0;
R2 : Ohms := 1.0;
begin
v := A * (R1 + R2);
put_line(V'Img);
end main;
If the types the types are defined as new Float
I get the following exception during compilation:
main.adb:22:12: error: invalid operand types for operator "*"
main.adb:22:12: error: left operand has type "Amps" defined at line 5
main.adb:22:12: error: right operand has type "Ohms" defined at line 6
I expected the use of type with Volts to define a new type that was incompatible with the other types as it wasn't an explicit subtype of the fixed point type.