sandbox/prada2012/ch02/print_roots2.adb

33 lines
722 B
Ada
Raw Normal View History

2019-09-16 15:59:50 +00:00
-- print_roots2 demonstrates runtime exceptions.
with Ada.Text_IO;
with Ada.Float_Text_IO;
2019-09-24 16:40:00 +00:00
with Ada.Numerics;
2019-09-16 15:59:50 +00:00
with Ada.Numerics.Generic_Elementary_Functions;
2019-09-24 16:40:00 +00:00
procedure Print_Roots2 is
2019-09-16 15:59:50 +00:00
use Ada.Text_IO;
use Ada.Float_Text_IO;
2019-09-24 16:40:00 +00:00
use Ada.Numerics;
2019-09-16 15:59:50 +00:00
package Numerics is new Ada.Numerics.Generic_Elementary_Functions(Float);
use Numerics;
X: Float;
begin
Put_Line("Roots of various numbers");
New_Line(1);
loop
Get(X);
exit when X = 0.0;
2019-09-24 16:40:00 +00:00
begin
Put("Root of "); Put(X); Put(" is ");
exception
when Ada.Numerics.Argument_Error =>
Put("not calculable: X must be >= 0");
when Constraint_Error =>
Put("not calculable: X must be >= 0");
end;
2019-09-16 15:59:50 +00:00
Put(Sqrt(X));
New_Line;
end loop;
2019-09-24 16:40:00 +00:00
end Print_Roots2;