home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 September / Chip_2001-09_cd1.bin / zkuste / delphi / kolekce / d12345 / MISC.ZIP / NoMath.pas < prev    next >
Pascal/Delphi Source File  |  2001-05-02  |  3KB  |  123 lines

  1. unit NoMath;
  2.  
  3. {$I Misc.inc}
  4.  
  5. {-----------------------------------------------------------------------------
  6. The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
  7.  
  8. http://www.mozilla.org/MPL/MPL-1.1.html
  9.  
  10. Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License.
  11.  
  12. The Original Code is: NoMath.pas, released 10 Jan 2001.
  13. Portions were originally present in Misc.pas.
  14.  
  15. The Initial Developer of the Original Code is Mat Ballard.
  16. Portions created by Mat Ballard are Copyright (C) 1999 Mat Ballard.
  17. Portions created by Microsoft are Copyright (C) 1998, 1999 Microsoft Corp.
  18. All Rights Reserved.
  19.  
  20. Contributor(s): Mat Ballard                 e-mail: mat.ballard@chemware.hypermart.net.
  21.  
  22. Last Modified: 01/12/2001
  23. Current Version: 2.00
  24.  
  25. You may retrieve the latest version of this file from:
  26.  
  27.         http://Chemware.hypermart.net/
  28.  
  29. This work was created with the Project JEDI VCL guidelines:
  30.  
  31.         http://www.delphi-jedi.org/Jedi:VCLVCL
  32.  
  33. in mind.
  34.  
  35.  
  36. Purpose:
  37. Collection of routines to substitute for the Math unit in the Pro versions.
  38.  
  39. Known Issues:
  40. -----------------------------------------------------------------------------}
  41.  
  42. interface
  43.  
  44. uses
  45.   Classes, SysUtils
  46. {$IFDEF WINDOWS}
  47. {$ENDIF}
  48. {$IFDEF WIN32}
  49. {$ENDIF}
  50. {$IFDEF LINUX}
  51. {$ENDIF}
  52.   ;
  53.  
  54. {type}
  55.  
  56.   function Floor(X: Extended): Integer;
  57.   function IntPower(Base: Extended; Exponent: Integer): Extended;
  58.   function Log10(X: Extended): Extended;
  59.   function Power(Base, Exponent: Extended): Extended;
  60.   function Min(A, B: Integer): Integer;
  61.   function Max(A, B: Integer): Integer;
  62.   procedure SinCos(Theta: Extended; var SinTheta, CosTheta: Extended);
  63.  
  64. const
  65.   TWO_PI = 6.28318530717958; {6476925286766559}
  66.  
  67. implementation
  68.  
  69. {The following routines are also found in the Math unit in the Pro versions.
  70.  However, the Borland versions are far more efficient.}
  71.  
  72. function Log10(X: Extended): Extended;
  73. begin
  74. {divide by ln(10):}
  75.   Result :=  Ln(X) / 2.3025850929940456840179914546844;
  76. end;
  77.  
  78. function IntPower(Base: Extended; Exponent: Integer): Extended;
  79. begin
  80.   Result := Power(Base, Exponent);
  81. end;
  82.  
  83. function Power(Base, Exponent: Extended): Extended;
  84. begin
  85.   if Exponent = 0.0 then
  86.     Result := 1.0               { n**0 = 1 }
  87.   else if (Base = 0.0) and (Exponent > 0.0) then
  88.     Result := 0.0               { 0**n = 0, n > 0 }
  89.   else
  90.     Result := Exp(Exponent * Ln(Base))
  91. end;
  92.  
  93. function Floor(X: Extended): Integer;
  94. begin
  95.   Result := Integer(Trunc(X));
  96.   if Frac(X) < 0 then
  97.     Result := Result - 1;
  98. end;
  99.  
  100. function Min(A, B: Integer): Integer;
  101. begin
  102.   if (A < B) then
  103.     Result := A
  104.    else
  105.     Result := B;
  106. end;
  107.  
  108. function Max(A, B: Integer): Integer;
  109. begin
  110.   if (A > B) then
  111.     Result := A
  112.    else
  113.     Result := B;
  114. end;
  115.  
  116. procedure SinCos(Theta: Extended; var SinTheta, CosTheta: Extended);
  117. begin
  118.   SinTheta := Sin(Theta);
  119.   CosTheta := Cos(Theta);
  120. end;
  121.  
  122. end.
  123.