Length of an arc between two angles: Difference between revisions

Content added Content deleted
(→‎{{header|Ada}}: added a short simple Ada program and one with different types for degrees and radians)
Line 99: Line 99:
with ada.float_text_io; use ada.float_text_io; -- for put()
with ada.float_text_io; use ada.float_text_io; -- for put()
with ada.numerics; use ada.numerics; -- for pi
with ada.numerics; use ada.numerics; -- for pi
with ada.text_io; use ada.text_io; -- for put_line()
with ada.text_io; use ada.text_io; -- for new_line


procedure arc_length_simple is
procedure arc_length_simple is

function arc_length(radius, deg1, deg2: Float) return Float is
function arc_length(radius, deg1, deg2: Float) return Float is
((360.0 - abs(deg1 - deg2)) * pi * radius / 180.0);
((360.0 - abs(deg1 - deg2)) * pi * radius / 180.0);

begin
begin
put(arc_length(10.0, 120.0, 10.0), fore=>0, aft=>15, exp=>0);
put(arc_length(10.0, 120.0, 10.0), fore=>0, aft=>15, exp=>0);
put_line("");
new_line;
end arc_length_simple;
end arc_length_simple;
</syntaxhighlight>
</syntaxhighlight>
Line 114: Line 116:
with ada.float_text_io; use ada.float_text_io; -- for put()
with ada.float_text_io; use ada.float_text_io; -- for put()
with ada.numerics; use ada.numerics; -- for pi
with ada.numerics; use ada.numerics; -- for pi
with ada.text_io; use ada.text_io; -- for put_line()
with ada.text_io; use ada.text_io; -- for new_line


procedure arc_length_both is
procedure arc_length_both is
type Degree is new Float;
type Degree is new Float;
type Radian is new Float;
type Radian is new Float;

function arc_length(radius: Float; deg1, deg2: Degree) return Float is
function arc_length(radius: Float; deg1, deg2: Degree) return Float is
((360.0 - abs(Float(deg1) - Float(deg2))) * radius * pi / 180.0);
((360.0 - abs(Float(deg1) - Float(deg2))) * radius * pi / 180.0);

function arc_length(radius: Float; rad1, rad2: Radian) return Float is
function arc_length(radius: Float; rad1, rad2: Radian) return Float is
((2.0 * pi - abs(Float(rad1) - Float(rad2))) * radius);
((2.0 * pi - abs(Float(rad1) - Float(rad2))) * radius);

d1 : Degree := 120.0;
d1 : Degree := 120.0;
d2 : Degree := 10.0;
d2 : Degree := 10.0;
Line 129: Line 134:
begin
begin
put(arc_length(10.0, d1, d2), fore=>0, aft=>15, exp=>0);
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(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
-- 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);
-- put(arc_length(10.0, d1, r2), fore=>0, aft=>15, exp=>0);