home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / ECO30603.ZIP / ECO30603.LZH / ECOLIBII / ECO_CALC.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-03-08  |  16.6 KB  |  520 lines

  1. {
  2.     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  3.     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  4.     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  5.     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  6.     ▓▓▓▓▓▓▓▓·──                                              ──·▓▓▓▓▓▓▓▓▓▓▓
  7.     ▓▓▓▓▓▓▓▓│                                                  │░░▓▓▓▓▓▓▓▓▓
  8.     ▓▓▓▓▓▓▓▓   Unit was conceived, designed and written         ░░▓▓▓▓▓▓▓▓▓
  9.     ▓▓▓▓▓▓▓▓   by Floor A.C. Naaijkens for                      ░░▓▓▓▓▓▓▓▓▓
  10.     ▓▓▓▓▓▓▓▓   UltiHouse Software / The ECO Group.              ░░▓▓▓▓▓▓▓▓▓
  11.     ▓▓▓▓▓▓▓▓                                                    ░░▓▓▓▓▓▓▓▓▓
  12.     ▓▓▓▓▓▓▓▓   (C) MCMXCII by EUROCON PANATIONAL CORPORATION.   ░░▓▓▓▓▓▓▓▓▓
  13.     ▓▓▓▓▓▓▓▓   All Rights Reserved for The ECO Group.           ░░▓▓▓▓▓▓▓▓▓
  14.     ▓▓▓▓▓▓▓▓                                                    ░░▓▓▓▓▓▓▓▓▓
  15.     ▓▓▓▓▓▓▓▓│                                                  │░░▓▓▓▓▓▓▓▓▓
  16.     ▓▓▓▓▓▓▓▓·──                                              ──·░░▓▓▓▓▓▓▓▓▓
  17.     ▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓▓▓▓▓
  18.     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  19.     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  20.     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  21. }
  22. {$O+}
  23. {
  24.                        f i l e    i n f o r m a t i o n
  25.  
  26. * description
  27. supplies missing trigonometric functions for turbo pascal 5.5. also
  28. provides hyperbolic, logarithmic, power, and root functions. all trig
  29. functions accessibile by radians, decimal degrees, degrees-minutes-seconds
  30. and a global degreetype.
  31.  
  32. }
  33. unit eco_calc;
  34.  
  35. (*  eco_calc  -  supplies missing trigonometric functions for Borland Pascal 7.0
  36.  *           also provides hyperbolic, logarithmic, power, and root functions.
  37.  *           all trig functions accessible by radians, decimal degrees,
  38.  *           degrees-minutes-seconds, and a global degreetype.  conversions
  39.  *           between these are supplied.
  40.  *
  41.  *)
  42.  
  43. interface
  44.  
  45. type
  46.   degreetype =  record
  47.                   degrees, minutes, seconds : real;
  48.                 end;
  49. const
  50.   infinity = 9.9999999999e+37;
  51.  
  52. {  radians  }
  53. { sin, cos, and arctan are predefined }
  54.  
  55. function tan( radians : real ) : real;
  56. function arcsin( invalue : real ) : real;
  57. function arccos( invalue : real ) : real;
  58.  
  59. {  degrees, expressed as a real number  }
  60.  
  61. function degreestoradians( degrees : real ) : real;
  62. function radianstodegrees( radians : real ) : real;
  63. function sin_degree( degrees : real ) : real;
  64. function cos_degree( degrees : real ) : real;
  65. function tan_degree( degrees : real ) : real;
  66. function arcsin_degree( degrees : real ) : real;
  67. function arccos_degree( degrees : real ) : real;
  68. function arctan_degree( degrees : real ) : real;
  69.  
  70. {  degrees, in degrees, minutes, and seconds, as real numbers  }
  71.  
  72. function degreepartstodegrees( degrees, minutes, seconds : real ) : real;
  73. function degreepartstoradians( degrees, minutes, seconds : real ) : real;
  74. procedure degreestodegreeparts( degreesin : real;
  75.                                 var degrees, minutes, seconds : real );
  76. procedure radianstodegreeparts( radians : real;
  77.                                 var degrees, minutes, seconds : real );
  78. function sin_degreeparts( degrees, minutes, seconds : real ) : real;
  79. function cos_degreeparts( degrees, minutes, seconds : real ) : real;
  80. function tan_degreeparts( degrees, minutes, seconds : real ) : real;
  81. function arcsin_degreeparts( degrees, minutes, seconds : real ) : real;
  82. function arccos_degreeparts( degrees, minutes, seconds : real ) : real;
  83. function arctan_degreeparts( degrees, minutes, seconds : real ) : real;
  84.  
  85. {  degrees, expressed as degreetype ( reals in record ) }
  86.  
  87. function degreetypetodegrees( degreevar : degreetype ) : real;
  88. function degreetypetoradians( degreevar : degreetype ) : real;
  89. procedure degreetypetodegreeparts( degreevar : degreetype;
  90.                                    var degrees, minutes, seconds : real );
  91. procedure degreestodegreetype( degrees : real; var degreevar : degreetype );
  92. procedure radianstodegreetype( radians : real; var degreevar : degreetype );
  93. procedure degreepartstodegreetype( degrees, minutes, seconds : real;
  94.                                    var degreevar : degreetype );
  95. function sin_degreetype( degreevar : degreetype ) : real;
  96. function cos_degreetype( degreevar : degreetype ) : real;
  97. function tan_degreetype( degreevar : degreetype ) : real;
  98. function arcsin_degreetype( degreevar : degreetype ) : real;
  99. function arccos_degreetype( degreevar : degreetype ) : real;
  100. function arctan_degreetype( degreevar : degreetype ) : real;
  101.  
  102. {  hyperbolic functions  }
  103.  
  104. function sinh( invalue : real ) : real;
  105. function cosh( invalue : real ) : real;
  106. function tanh( invalue : real ) : real;
  107. function coth( invalue : real ) : real;
  108. function sech( invalue : real ) : real;
  109. function csch( invalue : real ) : real;
  110. function arcsinh( invalue : real ) : real;
  111. function arccosh( invalue : real ) : real;
  112. function arctanh( invalue : real ) : real;
  113. function arccoth( invalue : real ) : real;
  114. function arcsech( invalue : real ) : real;
  115. function arccsch( invalue : real ) : real;
  116.  
  117. {  logarithms, powers, and roots  }
  118.  
  119. { e to the x  is  exp() }
  120. { natural log is  ln()  }
  121. function log10( innumber : real ) : real;
  122. function log( base, innumber : real ) : real;  { log of any base }
  123. function power( innumber, exponent : real ) : real;
  124. function root( innumber, theroot : real ) : real;
  125.  
  126.  
  127. {----------------------------------------------------------------------}
  128. implementation
  129.  
  130. const
  131.   radiansperdegree =  0.017453292520;
  132.   degreesperradian = 57.295779513;
  133.   minutesperdegree =   60.0;
  134.   secondsperdegree = 3600.0;
  135.   secondsperminute = 60.0;
  136.   lnof10 = 2.3025850930;
  137.  
  138. {-----------}
  139. {  radians  }
  140. {-----------}
  141.  
  142. { sin, cos, and arctan are predefined }
  143.  
  144. function tan { ( radians : real ) : real };
  145.   { note: returns infinity where appropriate }
  146.   var
  147.     cosineval : real;
  148.     tangentval : real;
  149.   begin
  150.   cosineval := cos( radians );
  151.   if cosineval = 0.0 then
  152.     tan := infinity
  153.   else
  154.     begin
  155.     tangentval := sin( radians ) / cosineval;
  156.     if ( tangentval < -infinity ) or ( tangentval > infinity ) then
  157.       tan := infinity
  158.     else
  159.       tan := tangentval;
  160.     end;
  161.   end;
  162.  
  163. function arcsin{ ( invalue : real ) : real };
  164.   { notes: 1) exceeding input range of -1 through +1 will cause runtime error }
  165.   {        2) only returns principal values                                   }
  166.   {             ( -pi/2 through pi/2 radians ) ( -90 through +90 degrees )    }
  167.   begin
  168.   if abs( invalue ) = 1.0 then
  169.     arcsin := pi / 2.0
  170.   else
  171.     arcsin := arctan( invalue / sqrt( 1 - invalue * invalue ) );
  172.   end;
  173.  
  174. function arccos{ ( invalue : real ) : real };
  175.   { notes: 1) exceeding input range of -1 through +1 will cause runtime error }
  176.   {        2) only returns principal values                                   }
  177.   {             ( 0 through pi radians ) ( 0 through +180 degrees )           }
  178.   var
  179.     result : real;
  180.   begin
  181.   if invalue = 0.0 then
  182.     arccos := pi / 2.0
  183.   else
  184.     begin
  185.     result := arctan( sqrt( 1 - invalue * invalue ) / invalue );
  186.     if invalue < 0.0 then
  187.       arccos := result + pi
  188.     else
  189.       arccos := result;
  190.     end;
  191.   end;
  192.  
  193. {---------------------------------------}
  194. {  degrees, expressed as a real number  }
  195. {---------------------------------------}
  196.  
  197. function degreestoradians{ ( degrees : real ) : real };
  198.   begin
  199.   degreestoradians := degrees * radiansperdegree;
  200.   end;
  201.  
  202. function radianstodegrees{ ( radians : real ) : real };
  203.   begin
  204.   radianstodegrees := radians * degreesperradian;
  205.   end;
  206.  
  207. function sin_degree{ ( degrees : real ) : real };
  208.   begin
  209.   sin_degree := sin( degreestoradians( degrees ) );
  210.   end;
  211.  
  212. function cos_degree{ ( degrees : real ) : real };
  213.   begin
  214.   cos_degree := cos( degreestoradians( degrees ) );
  215.   end;
  216.  
  217. function tan_degree{ ( degrees : real ) : real };
  218.   begin
  219.   tan_degree := tan( degreestoradians( degrees ) );
  220.   end;
  221.  
  222. function arcsin_degree{ ( degrees : real ) : real };
  223.   begin
  224.   arcsin_degree := arcsin( degreestoradians( degrees ) );
  225.   end;
  226.  
  227. function arccos_degree{ ( degrees : real ) : real };
  228.   begin
  229.   arccos_degree := arccos( degreestoradians( degrees ) );
  230.   end;
  231.  
  232. function arctan_degree{ ( degrees : real ) : real };
  233.   begin
  234.   arctan_degree := arctan( degreestoradians( degrees ) );
  235.   end;
  236.  
  237. {--------------------------------------------------------------}
  238. {  degrees, in degrees, minutes, and seconds, as real numbers  }
  239. {--------------------------------------------------------------}
  240.  
  241. function degreepartstodegrees{ ( degrees, minutes, seconds : real ) : real };
  242.   begin
  243.   degreepartstodegrees := degrees + ( minutes / minutesperdegree ) +
  244.                                        ( seconds / secondsperdegree );
  245.   end;
  246.  
  247. function degreepartstoradians{ ( degrees, minutes, seconds : real ) : real };
  248.   begin
  249.   degreepartstoradians := degreestoradians( degreepartstodegrees( degrees,
  250.                                                         minutes, seconds ) );
  251.   end;
  252.  
  253. procedure degreestodegreeparts{ ( degreesin : real;
  254.                                   var degrees, minutes, seconds : real ) };
  255.   begin
  256.   degrees := int( degreesin );
  257.   minutes := ( degreesin - degrees ) * minutesperdegree;
  258.   seconds := frac( minutes );
  259.   minutes := int( minutes );
  260.   seconds := seconds * secondsperminute;
  261.   end;
  262.  
  263. procedure radianstodegreeparts{ ( radians : real;
  264.                                   var degrees, minutes, seconds : real ) };
  265.   begin
  266.   degreestodegreeparts( radianstodegrees( radians ),
  267.                           degrees, minutes, seconds );
  268.   end;
  269.  
  270. function sin_degreeparts{ ( degrees, minutes, seconds : real ) : real };
  271.   begin
  272.   sin_degreeparts := sin( degreepartstoradians( degrees, minutes, seconds ) );
  273.   end;
  274.  
  275. function cos_degreeparts{ ( degrees, minutes, seconds : real ) : real };
  276.   begin
  277.   cos_degreeparts := cos( degreepartstoradians( degrees, minutes, seconds ) );
  278.   end;
  279.  
  280. function tan_degreeparts{ ( degrees, minutes, seconds : real ) : real };
  281.   begin
  282.   tan_degreeparts := tan( degreepartstoradians( degrees, minutes, seconds ) );
  283.   end;
  284.  
  285. function arcsin_degreeparts{ ( degrees, minutes, seconds : real ) : real };
  286.   begin
  287.   arcsin_degreeparts := arcsin( degreepartstoradians( degrees,
  288.                                                       minutes, seconds ) );
  289.   end;
  290.  
  291. function arccos_degreeparts{ ( degrees, minutes, seconds : real ) : real };
  292.   begin
  293.   arccos_degreeparts := arccos( degreepartstoradians( degrees,
  294.                                                       minutes, seconds ) );
  295.   end;
  296.  
  297. function arctan_degreeparts{ ( degrees, minutes, seconds : real ) : real };
  298.   begin
  299.   arctan_degreeparts := arctan( degreepartstoradians( degrees,
  300.                                                       minutes, seconds ) );
  301.   end;
  302.  
  303. {-------------------------------------------------------}
  304. {  degrees, expressed as degreetype ( reals in record ) }
  305. {-------------------------------------------------------}
  306.  
  307. function degreetypetodegrees{ ( degreevar : degreetype ) : real };
  308.   begin
  309.   degreetypetodegrees := degreepartstodegrees( degreevar.degrees,
  310.                                        degreevar.minutes, degreevar.seconds );
  311.   end;
  312.  
  313. function degreetypetoradians{ ( degreevar : degreetype ) : real };
  314.   begin
  315.   degreetypetoradians := degreestoradians( degreetypetodegrees( degreevar ) );
  316.   end;
  317.  
  318. procedure degreetypetodegreeparts{ ( degreevar : degreetype;
  319.                                      var degrees, minutes, seconds : real ) };
  320.   begin
  321.   degrees := degreevar.degrees;
  322.   minutes := degreevar.minutes;
  323.   seconds := degreevar.seconds;
  324.   end;
  325.  
  326. procedure degreestodegreetype{ ( degrees : real; var degreevar : degreetype )};
  327.   begin
  328.   degreestodegreeparts( degrees, degreevar.degrees,
  329.                         degreevar.minutes, degreevar.seconds );
  330.   end;
  331.  
  332. procedure radianstodegreetype{ ( radians : real; var degreevar : degreetype )};
  333.   begin
  334.   degreestodegreeparts( radianstodegrees( radians ), degreevar.degrees,
  335.                         degreevar.minutes, degreevar.seconds );
  336.   end;
  337.  
  338. procedure degreepartstodegreetype{ ( degrees, minutes, seconds : real;
  339.                                      var degreevar : degreetype ) };
  340.   begin
  341.   degreevar.degrees := degrees;
  342.   degreevar.minutes := minutes;
  343.   degreevar.seconds := seconds;
  344.   end;
  345.  
  346. function sin_degreetype{ ( degreevar : degreetype ) : real };
  347.   begin
  348.   sin_degreetype := sin( degreetypetoradians( degreevar ) );
  349.   end;
  350.  
  351. function cos_degreetype{ ( degreevar : degreetype ) : real };
  352.   begin
  353.   cos_degreetype := cos( degreetypetoradians( degreevar ) );
  354.   end;
  355.  
  356. function tan_degreetype{ ( degreevar : degreetype ) : real };
  357.   begin
  358.   tan_degreetype := tan( degreetypetoradians( degreevar ) );
  359.   end;
  360.  
  361. function arcsin_degreetype{ ( degreevar : degreetype ) : real };
  362.   begin
  363.   arcsin_degreetype := arcsin( degreetypetoradians( degreevar ) );
  364.   end;
  365.  
  366. function arccos_degreetype{ ( degreevar : degreetype ) : real };
  367.   begin
  368.   arccos_degreetype := arccos( degreetypetoradians( degreevar ) );
  369.   end;
  370.  
  371. function arctan_degreetype{ ( degreevar : degreetype ) : real };
  372.   begin
  373.   arctan_degreetype := arctan( degreetypetoradians( degreevar ) );
  374.   end;
  375.  
  376. {------------------------}
  377. {  hyperbolic functions  }
  378. {------------------------}
  379.  
  380. function sinh{ ( invalue : real ) : real };
  381.   const
  382.     maxvalue = 88.029691931;  { exceeds standard turbo precision }
  383.   var
  384.     sign : real;
  385.   begin
  386.   sign := 1.0;
  387.   if invalue < 0 then
  388.     begin
  389.     sign := -1.0;
  390.     invalue := -invalue;
  391.     end;
  392.   if invalue > maxvalue then
  393.     sinh := infinity
  394.   else
  395.     sinh := ( exp( invalue ) - exp( -invalue ) ) / 2.0 * sign;
  396.   end;
  397.  
  398. function cosh{ ( invalue : real ) : real };
  399.   const
  400.     maxvalue = 88.029691931;  { exceeds standard turbo precision }
  401.   begin
  402.   invalue := abs( invalue );
  403.   if invalue > maxvalue then
  404.     cosh := infinity
  405.   else
  406.     cosh := ( exp( invalue ) + exp( -invalue ) ) / 2.0;
  407.   end;
  408.  
  409. function tanh{ ( invalue : real ) : real };
  410.   begin
  411.   tanh := sinh( invalue ) / cosh( invalue );
  412.   end;
  413.  
  414. function coth{ ( invalue : real ) : real };
  415.   begin
  416.   coth := cosh( invalue ) / sinh( invalue );
  417.   end;
  418.  
  419. function sech{ ( invalue : real ) : real };
  420.   begin
  421.   sech := 1.0 / cosh( invalue );
  422.   end;
  423.  
  424. function csch{ ( invalue : real ) : real };
  425.   begin
  426.   csch := 1.0 / sinh( invalue );
  427.   end;
  428.  
  429. function arcsinh{ ( invalue : real ) : real };
  430.   var
  431.     sign : real;
  432.   begin
  433.   sign := 1.0;
  434.   if invalue < 0 then
  435.     begin
  436.     sign := -1.0;
  437.     invalue := -invalue;
  438.     end;
  439.   arcsinh := ln( invalue + sqrt( invalue*invalue + 1 ) ) * sign;
  440.   end;
  441.  
  442. function arccosh{ ( invalue : real ) : real };
  443.   var
  444.     sign : real;
  445.   begin
  446.   sign := 1.0;
  447.   if invalue < 0 then
  448.     begin
  449.     sign := -1.0;
  450.     invalue := -invalue;
  451.     end;
  452.   arccosh := ln( invalue + sqrt( invalue*invalue - 1 ) ) * sign;
  453.   end;
  454.  
  455. function arctanh{ ( invalue : real ) : real };
  456.   var
  457.     sign : real;
  458.   begin
  459.   sign := 1.0;
  460.   if invalue < 0 then
  461.     begin
  462.     sign := -1.0;
  463.     invalue := -invalue;
  464.     end;
  465.   arctanh := ln( ( 1 + invalue ) / ( 1 - invalue ) ) / 2.0 * sign;
  466.   end;
  467.  
  468. function arccoth{ ( invalue : real ) : real };
  469.   begin
  470.   arccoth := arctanh( 1.0 / invalue );
  471.   end;
  472.  
  473. function arcsech{ ( invalue : real ) : real };
  474.   begin
  475.   arcsech := arccosh( 1.0 / invalue );
  476.   end;
  477.  
  478. function arccsch{ ( invalue : real ) : real };
  479.   begin
  480.   arccsch := arcsinh( 1.0 / invalue );
  481.   end;
  482.  
  483. {---------------------------------}
  484. {  logarithms, powers, and roots  }
  485. {---------------------------------}
  486.  
  487. { e to the x  is  exp() }
  488. { natural log is  ln()  }
  489.  
  490. function log10{ ( innumber : real ) : real };
  491.   begin
  492.   log10 := ln( innumber ) / lnof10;
  493.   end;
  494.  
  495. function log{ ( base, innumber : real ) : real };  { log of any base }
  496.   begin
  497.   log := ln( innumber ) / ln( base );
  498.   end;
  499.  
  500. function power{ ( innumber, exponent : real ) : real };
  501.   begin
  502.   if innumber > 0.0 then
  503.     power := exp( exponent * ln( innumber ) )
  504.   else if innumber = 0.0 then
  505.     power := 1.0
  506.   else { we don'T force a runtime error, we define a function to provide
  507.          negative logarithms! }
  508.     if exponent=trunc(exponent) then
  509.       power := (-2*(trunc(exponent) mod 2)+1) * exp(exponent * ln( -innumber ) )
  510.       else power := trunc(1/(exponent-exponent));
  511.               { now we generate a runtime error }
  512.   end;
  513.  
  514. function root{ ( innumber, theroot : real ) : real };
  515.   begin
  516.   root := power( innumber, ( 1.0 / theroot ) );
  517.   end;
  518.  
  519. end. { unit ptd_calc }
  520.