Angles (geometric), normalization and conversion: Difference between revisions

Added Algol W
(BBC BASIC entry.)
(Added Algol W)
 
(2 intermediate revisions by the same user not shown)
Line 217:
Radians Normalized Degrees Gradians Mils
───────────────────────────────────────────────────────────────────────────────────
-2.0000000 -2.0000000 -114.5915590 -127.3239545 -2037.1832716
-1.0000000 -1.0000000 -57.2957795 -63.6619772 -1018.5916358
0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
1.0000000 1.0000000 57.2957795 63.6619772 1018.5916358
2.0000000 2.0000000 114.5915590 127.3239545 2037.1832716
6.2831853 6.2831853 359.9999996 399.9999995 6399.9999927
16.0000000 3.4336294 196.7324722 218.5916358 3497.4661726
57.2957795 0.7471117 42.8063493 47.5626103 761.0017647
359.0000000 0.8584375 49.1848452 54.6498280 874.3972479
399.0000000 3.1593256 181.0160257 201.1289175 3218.0626795
6399.0000000 2.7173573 155.6931042 172.9923380 2767.8774082
1000000.0000000 5.9256211 339.5130823 377.2367581 6035.7881302
</pre>
 
=={{header|ALGOL 68}}==
{{Trans|11l|using an array of procedures to simplify the output}}
<syntaxhighlight lang="algol68">
BEGIN # Angles (geometric), normalization and conversion - translated from the 11l sample #
 
[]REAL values = ( -2, -1, 0, 1, 2, 6.2831853, 16, 57.2957795, 359, 399, 6399, 1000000 );
 
PROC norm = ( REAL x, y )REAL:
BEGIN
INT n = ENTIER ( ABS x / ABS y );
REAL r := x - ( n * y );
r
END # norm # ;
PROC normd = ( REAL x )REAL: norm( x, 360 );
PROC normg = ( REAL x )REAL: norm( x, 400 );
PROC normm = ( REAL x )REAL: norm( x, 6400 );
PROC normr = ( REAL x )REAL: norm( x, 2 * pi );
 
PROC d2g = ( REAL x )REAL: normd( x ) * 10 / 9;
PROC d2m = ( REAL x )REAL: normd( x ) * 160 / 9;
PROC d2r = ( REAL x )REAL: normd( x ) * pi / 180;
 
PROC g2d = ( REAL x )REAL: normg( x ) * 9 / 10;
PROC g2m = ( REAL x )REAL: normg( x ) * 16;
PROC g2r = ( REAL x )REAL: normg( x ) * pi / 200;
 
PROC m2d = ( REAL x )REAL: normm( x ) * 9 / 160;
PROC m2g = ( REAL x )REAL: normm( x ) / 16;
PROC m2r = ( REAL x )REAL: normm( x ) * pi / 3200;
 
PROC r2d = ( REAL x )REAL: normr( x ) * 180 / pi;
PROC r2g = ( REAL x )REAL: normr( x ) * 200 / pi;
PROC r2m = ( REAL x )REAL: normr( x ) * 3200 / pi;
 
STRING underline = "----------------------------------------------------------------------------------";
PROC f7d7 = ( REAL v )STRING: fixed( v, -15, 7 );
 
PROC print values = ( STRING heading, []PROC(REAL)REAL f )VOID:
BEGIN
print( ( heading, newline ) );
print( ( underline, newline ) );
FOR i FROM LWB values TO UPB values DO
REAL v = values[ i ];
print( ( f7d7( v ) ) );
FOR p FROM LWB f TO UPB f DO
print( ( " ", f7d7( f[ p ]( v ) ) ) )
OD;
print( ( newline ) )
OD;
print( ( newline ) )
END # print values # ;
 
print values( " Degrees Normalized Gradians Mils Radians"
, ( normd, d2g, d2m, d2r )
);
print values( " Gradians Normalized Degrees Mils Radians"
, ( normg, g2d, g2m, g2r )
);
print values( " Mils Normalized Degrees Gradians Radians"
, ( normm, m2d, m2g, m2r )
);
print values( " Radians Normalized Degrees Gradians Mils"
, ( normr, r2d, r2g, r2m )
)
 
END
</syntaxhighlight>
{{out}}
<pre>
Degrees Normalized Gradians Mils Radians
----------------------------------------------------------------------------------
-2.0000000 -2.0000000 -2.2222222 -35.5555556 -0.0349066
-1.0000000 -1.0000000 -1.1111111 -17.7777778 -0.0174533
0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
1.0000000 1.0000000 1.1111111 17.7777778 0.0174533
2.0000000 2.0000000 2.2222222 35.5555556 0.0349066
6.2831853 6.2831853 6.9813170 111.7010720 0.1096623
16.0000000 16.0000000 17.7777778 284.4444444 0.2792527
57.2957795 57.2957795 63.6619772 1018.5916356 1.0000000
359.0000000 359.0000000 398.8888889 6382.2222222 6.2657320
399.0000000 39.0000000 43.3333333 693.3333333 0.6806784
6399.0000000 279.0000000 310.0000000 4960.0000000 4.8694686
1000000.0000000 280.0000000 311.1111111 4977.7777778 4.8869219
 
Gradians Normalized Degrees Mils Radians
----------------------------------------------------------------------------------
-2.0000000 -2.0000000 -1.8000000 -32.0000000 -0.0314159
-1.0000000 -1.0000000 -0.9000000 -16.0000000 -0.0157080
0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
1.0000000 1.0000000 0.9000000 16.0000000 0.0157080
2.0000000 2.0000000 1.8000000 32.0000000 0.0314159
6.2831853 6.2831853 5.6548668 100.5309648 0.0986960
16.0000000 16.0000000 14.4000000 256.0000000 0.2513274
57.2957795 57.2957795 51.5662015 916.7324720 0.9000000
359.0000000 359.0000000 323.1000000 5744.0000000 5.6391588
399.0000000 399.0000000 359.1000000 6384.0000000 6.2674773
6399.0000000 399.0000000 359.1000000 6384.0000000 6.2674773
1000000.0000000 0.0000000 0.0000000 0.0000000 0.0000000
 
Mils Normalized Degrees Gradians Radians
----------------------------------------------------------------------------------
-2.0000000 -2.0000000 -0.1125000 -0.1250000 -0.0019635
-1.0000000 -1.0000000 -0.0562500 -0.0625000 -0.0009817
0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
1.0000000 1.0000000 0.0562500 0.0625000 0.0009817
2.0000000 2.0000000 0.1125000 0.1250000 0.0019635
6.2831853 6.2831853 0.3534292 0.3926991 0.0061685
16.0000000 16.0000000 0.9000000 1.0000000 0.0157080
57.2957795 57.2957795 3.2228876 3.5809862 0.0562500
359.0000000 359.0000000 20.1937500 22.4375000 0.3524474
399.0000000 399.0000000 22.4437500 24.9375000 0.3917173
6399.0000000 6399.0000000 359.9437500 399.9375000 6.2822036
1000000.0000000 1600.0000000 90.0000000 100.0000000 1.5707963
 
Radians Normalized Degrees Gradians Mils
----------------------------------------------------------------------------------
-2.0000000 -2.0000000 -114.5915590 -127.3239545 -2037.1832716
-1.0000000 -1.0000000 -57.2957795 -63.6619772 -1018.5916358
0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
1.0000000 1.0000000 57.2957795 63.6619772 1018.5916358
2.0000000 2.0000000 114.5915590 127.3239545 2037.1832716
6.2831853 6.2831853 359.9999996 399.9999995 6399.9999927
16.0000000 3.4336294 196.7324722 218.5916358 3497.4661726
57.2957795 0.7471117 42.8063493 47.5626103 761.0017647
359.0000000 0.8584375 49.1848452 54.6498280 874.3972479
399.0000000 3.1593256 181.0160257 201.1289175 3218.0626795
6399.0000000 2.7173573 155.6931042 172.9923380 2767.8774082
1000000.0000000 5.9256211 339.5130823 377.2367581 6035.7881302
</pre>
 
=={{header|ALGOL W}}==
{{Trans|ALGOL 68|which was a translation of 11l}}
Algol W doesn't have arrays of procedures so separate parameters for the four functions are used.
<syntaxhighlight lang="algolw">
begin % Angles (geometric), normalization and conversion %
% - translation of the Algol 68 translation of the 11l sample %
 
real procedure norm ( real value x, y ) ;
begin
integer n;
n := entier( abs x / abs y );
x - ( n * y )
end norm ;
real procedure normd ( real value x ) ; norm( x, 360 );
real procedure normg ( real value x ) ; norm( x, 400 );
real procedure normm ( real value x ) ; norm( x, 6400 );
real procedure normr ( real value x ) ; norm( x, 2 * pi );
 
real procedure d2g ( real value x ) ; normd( x ) * 10 / 9;
real procedure d2m ( real value x ) ; normd( x ) * 160 / 9;
real procedure d2r ( real value x ) ; normd( x ) * pi / 180;
 
real procedure g2d ( real value x ) ; normg( x ) * 9 / 10;
real procedure g2m ( real value x ) ; normg( x ) * 16;
real procedure g2r ( real value x ) ; normg( x ) * pi / 200;
 
real procedure m2d ( real value x ) ; normm( x ) * 9 / 160;
real procedure m2g ( real value x ) ; normm( x ) / 16;
real procedure m2r ( real value x ) ; normm( x ) * pi / 3200;
 
real procedure r2d ( real value x ) ; normr( x ) * 180 / pi;
real procedure r2g ( real value x ) ; normr( x ) * 200 / pi;
real procedure r2m ( real value x ) ; normr( x ) * 3200 / pi;
 
procedure writeonF7d7 ( real value v ) ; writeon( r_format := "A", r_w := 15, r_d := 7, s_w := 0, v );
 
procedure printValues ( string(82) value heading
; real procedure f1, f2, f3, f4
; real array values( * )
; integer value numberOfValues
) ;
begin
write( heading );
write( "----------------------------------------------------------------------------------" );
for i := 1 until numberOfValues do begin
real v;
v := values( i );
write();
writeonF7d7( v );
writeon( " " ); writeonF7d7( f1( v ) ); writeon( " " ); writeonF7d7( f2( v ) );
writeon( " " ); writeonF7d7( f3( v ) ); writeon( " " ); writeonF7d7( f4( v ) );
end for_i ;
write()
end printValues ;
 
real array values ( 1 :: 12 );
values( 1 ) := -2; values( 2 ) := -1; values( 3 ) := 0; values( 4 ) := 1; values( 5 ) := 2;
values( 6 ) := 6.2831853; values( 7 ) := 16; values( 8 ) := 57.2957795; values( 9 ) := 359;
values( 10 ) := 399; values( 11 ) := 6399; values( 12 ) := 1000000;
 
printValues( " Degrees Normalized Gradians Mils Radians"
, normd, d2g, d2m, d2r, values, 12
);
printValues( " Gradians Normalized Degrees Mils Radians"
, normg, g2d, g2m, g2r, values, 12
);
printValues( " Mils Normalized Degrees Gradians Radians"
, normm, m2d, m2g, m2r, values, 12
);
printValues( " Radians Normalized Degrees Gradians Mils"
, normr, r2d, r2g, r2m, values, 12
)
 
end.
</syntaxhighlight>
{{out}}
<pre>
Degrees Normalized Gradians Mils Radians
----------------------------------------------------------------------------------
-2.0000000 -2.0000000 -2.2222222 -35.5555556 -0.0349066
-1.0000000 -1.0000000 -1.1111111 -17.7777778 -0.0174533
0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
1.0000000 1.0000000 1.1111111 17.7777778 0.0174533
2.0000000 2.0000000 2.2222222 35.5555556 0.0349066
6.2831853 6.2831853 6.9813170 111.7010720 0.1096623
16.0000000 16.0000000 17.7777778 284.4444444 0.2792527
57.2957795 57.2957795 63.6619772 1018.5916356 1.0000000
359.0000000 359.0000000 398.8888889 6382.2222222 6.2657320
399.0000000 39.0000000 43.3333333 693.3333333 0.6806784
6399.0000000 279.0000000 310.0000000 4960.0000000 4.8694686
1000000.0000000 280.0000000 311.1111111 4977.7777778 4.8869219
 
Gradians Normalized Degrees Mils Radians
----------------------------------------------------------------------------------
-2.0000000 -2.0000000 -1.8000000 -32.0000000 -0.0314159
-1.0000000 -1.0000000 -0.9000000 -16.0000000 -0.0157080
0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
1.0000000 1.0000000 0.9000000 16.0000000 0.0157080
2.0000000 2.0000000 1.8000000 32.0000000 0.0314159
6.2831853 6.2831853 5.6548668 100.5309648 0.0986960
16.0000000 16.0000000 14.4000000 256.0000000 0.2513274
57.2957795 57.2957795 51.5662016 916.7324720 0.9000000
359.0000000 359.0000000 323.1000000 5744.0000000 5.6391588
399.0000000 399.0000000 359.1000000 6384.0000000 6.2674773
6399.0000000 399.0000000 359.1000000 6384.0000000 6.2674773
1000000.0000000 0.0000000 0.0000000 0.0000000 0.0000000
 
Mils Normalized Degrees Gradians Radians
----------------------------------------------------------------------------------
-2.0000000 -2.0000000 -0.1125000 -0.1250000 -0.0019635
-1.0000000 -1.0000000 -0.0562500 -0.0625000 -0.0009817
0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
1.0000000 1.0000000 0.0562500 0.0625000 0.0009817
2.0000000 2.0000000 0.1125000 0.1250000 0.0019635
6.2831853 6.2831853 0.3534292 0.3926991 0.0061685
16.0000000 16.0000000 0.9000000 1.0000000 0.0157080
57.2957795 57.2957795 3.2228876 3.5809862 0.0562500
359.0000000 359.0000000 20.1937500 22.4375000 0.3524474
399.0000000 399.0000000 22.4437500 24.9375000 0.3917173
6399.0000000 6399.0000000 359.9437500 399.9375000 6.2822036
1000000.0000000 1600.0000000 90.0000000 100.0000000 1.5707963
 
Radians Normalized Degrees Gradians Mils
----------------------------------------------------------------------------------
-2.0000000 -2.0000000 -114.5915590 -127.3239545 -2037.1832716
-1.0000000 -1.0000000 -57.2957795 -63.6619772 -1018.5916358
3,021

edits