Length of an arc between two angles: Difference between revisions

m
(→‎{{header|Ada}}: added a short simple Ada program and one with different types for degrees and radians)
Line 99:
with ada.float_text_io; use ada.float_text_io; -- for put()
with ada.numerics; use ada.numerics; -- for pi
with ada.text_io; use ada.text_io; -- for put_line()new_line
 
procedure arc_length_simple is
 
function arc_length(radius, deg1, deg2: Float) return Float is
((360.0 - abs(deg1 - deg2)) * pi * radius / 180.0);
 
begin
put(arc_length(10.0, 120.0, 10.0), fore=>0, aft=>15, exp=>0);
put_line("")new_line;
end arc_length_simple;
</syntaxhighlight>
Line 114 ⟶ 116:
with ada.float_text_io; use ada.float_text_io; -- for put()
with ada.numerics; use ada.numerics; -- for pi
with ada.text_io; use ada.text_io; -- for put_line()new_line
 
procedure arc_length_both is
type Degree is new Float;
type Radian is new Float;
 
function arc_length(radius: Float; deg1, deg2: Degree) return Float is
((360.0 - abs(Float(deg1) - Float(deg2))) * radius * pi / 180.0);
 
function arc_length(radius: Float; rad1, rad2: Radian) return Float is
((2.0 * pi - abs(Float(rad1) - Float(rad2))) * radius);
 
d1 : Degree := 120.0;
d2 : Degree := 10.0;
Line 129 ⟶ 134:
begin
put(arc_length(10.0, d1, d2), fore=>0, aft=>15, exp=>0);
put_line("")new_line;
put(arc_length(10.0, r1, r2), fore=>0, aft=>15, exp=>0);
put_line("")new_line;
-- Next line will not compile as you cannot mix Degree and Radian
-- put(arc_length(10.0, d1, r2), fore=>0, aft=>15, exp=>0);
27

edits