home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / kompon / d123456 / CHEMPLOT.ZIP / Misc / NoMath.pas < prev    next >
Pascal/Delphi Source File  |  2001-07-23  |  3KB  |  121 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. implementation
  65.  
  66. {The following routines are also found in the Math unit in the Pro versions.
  67.  However, the Borland versions are far more efficient.}
  68.  
  69. function Log10(X: Extended): Extended;
  70. begin
  71. {divide by ln(10):}
  72.   Result :=  Ln(X) / 2.3025850929940456840179914546844;
  73. end;
  74.  
  75. function IntPower(Base: Extended; Exponent: Integer): Extended;
  76. begin
  77.   Result := Power(Base, Exponent);
  78. end;
  79.  
  80. function Power(Base, Exponent: Extended): Extended;
  81. begin
  82.   if Exponent = 0.0 then
  83.     Result := 1.0               { n**0 = 1 }
  84.   else if (Base = 0.0) and (Exponent > 0.0) then
  85.     Result := 0.0               { 0**n = 0, n > 0 }
  86.   else
  87.     Result := Exp(Exponent * Ln(Base))
  88. end;
  89.  
  90. function Floor(X: Extended): Integer;
  91. begin
  92.   Result := Integer(Trunc(X));
  93.   if Frac(X) < 0 then
  94.     Result := Result - 1;
  95. end;
  96.  
  97. function Min(A, B: Integer): Integer;
  98. begin
  99.   if (A < B) then
  100.     Result := A
  101.    else
  102.     Result := B;
  103. end;
  104.  
  105. function Max(A, B: Integer): Integer;
  106. begin
  107.   if (A > B) then
  108.     Result := A
  109.    else
  110.     Result := B;
  111. end;
  112.  
  113. procedure SinCos(Theta: Extended; var SinTheta, CosTheta: Extended);
  114. begin
  115.   SinTheta := Sin(Theta);
  116.   CosTheta := Cos(Theta);
  117. end;
  118.  
  119. end.
  120.  
  121.