为什么伏特、安培和欧姆兼容?
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;
Run Code Online (Sandbox Code Playgroud)
如果类型被定义为new Float我在编译期间收到以下异常:
main.adb:22:12: error: …Run Code Online (Sandbox Code Playgroud)