**************************Math
数学单元
*********************************
Delphi / Kylix
跨平台运行时(
Runtime
)库
Copyright (c) 1996, 2001 Borland
软件
********************************************************************
这个单元包含高性能的算术、三角、对数、统计和金融方面的计算及
FPU
程序函数用于补充
Delphi
语言
System.pas
单元中的数学常规程序函数
参考:
1)
P.J. Plauger, "The Standard C Library", Prentice-Hall, 1992, Ch. 7.
《标准
C
程序库》
2)
W.J. Cody, Jr., and W. Waite, "Software Manual For the Elementary Functions", Prentice-Hall, 1980.
《软件手册初步》
3)
Namir Shammas, "C/C++ Mathematical Algorithms for Scientists and Engineers", McGraw-Hill, 1995, Ch 8.
《
C/C++
数学的运算法则对于科学家和工程师
》
4)
H.T. Lau, "A Numerical Library in C for Scientists and Engineers", CRC Press, 1994, Ch. 6.
《
C
语言中的数字的程序库对于科学家和工程师
》
5)
"Pentium(tm) Processor User's Manual, Volume 3: Architecture and Programming Manual", Intel, 1994
《
Pentium(tm)
处理器使用手册
,
第
3
册
:
体系结构和程序手册
》
注意
1)
对于有些函数,这个单元中涉及的概念或常数由
Earl F. Glynn (
www.efg2.com
)
和
Ray Lischner (
www.tempest-sw.com
)
提供。
2)
所有的角度参数三角函数的结果都用弧度表示
3)
下列大部分的三角和对数程序直接的映射到
Intel 80387 FPU
4)
浮点机指令、输入域、输出范围和错误处理主要由
FPU
硬件决定
5)
汇编程序中的代码支持
Pentium FPU
管线体系
l
常数
IEEE
浮点类型的范围
,
包括非正规的
1)
MinSingle =
1.5e-45;
最小
Single
数
2)
MaxSingle =
3.4e+38;
最大
Single
数
3)
MinDouble =
5.0e-324;
最小
Double
数
4)
MaxDouble =
1.7e+308;
最大
Double
数
5)
MinExtended =
3.4e-4932;
最小
Extended
数
6)
MaxExtended =
1.1e+4932;
最大
Extended
数
7)
MinComp = -9.223372036854775807e+18;
最小
Comp
数
8)
MaxComp =
9.223372036854775807e+18;
最大
Comp
数
下列常数不应当被用于比较关系,仅仅用于分配。若要用于比较关系请使用
IsNan
和
IsInfinity
函数。(已提供在后面)
9)
NaN =
0.0 / 0.0;
非数
(*$EXTERNALSYM NaN*)
(*$HPPEMIT 'static const Extended NaN = 0.0 / 0.0;'*)
10)
Infinity =
1.0 / 0.0;
正无穷大
(*$EXTERNALSYM Infinity*)
(*$HPPEMIT 'static const Extended Infinity = 1.0 / 0.0;'*)
11)
NegInfinity = -1.0 / 0.0;
负无穷大
(*$EXTERNALSYM NegInfinity*)
(*$HPPEMIT 'static const Extended NegInfinity = -1.0 / 0.0;'*)
一、
三角函数
1)
函数
ArcCos(const X: Extended): Extended;
(
IN: |X| <= 1
OUT: [0..PI]
弧度)
2)
函数
ArcSin(const X: Extended): Extended;
(
IN: |X| <= 1 OUT: [-PI/2..PI/2]
弧度)
3)
函数
ArcTan2(const Y, X: Extended): Extended; IN: |Y| < 2^64, |X| < 2^64, X <> 0
OUT: [-PI..PI]
弧度)。计算
ArcTan(Y/X),
并且返回一个正确象限内的角度
4)
过程
SinCos(const Theta: Extended; var Sin, Cos: Extended) register
;
SinCos
:比分别调用
Sin
和
Cos
计算同一个角度快两倍
5)
函数
Tan(const X: Extended): Extended;
6)
函数
Cotan(const X: Extended): Extended;
{ 1 / tan(X), X <> 0 }
7)
函数
Secant(const X: Extended): Extended;
{ 1 / cos(X) }
8)
函数
Cosecant(const X: Extended): Extended;
{ 1 / sin(X) }
9)
函数
Hypot(const X, Y: Extended): Extended;
{ Sqrt(X**2 + Y**2) }
二、
角度单位换算程序
1)
函数
RadToDeg(const Radians: Extended): Extended;
{
度数
:=
弧度
* 180 / PI
}
2)
函数
RadToGrad(const Radians: Extended): Extended; {
梯度
:=
弧度
* 200 / PI
}
3)
函数
RadToCycle(const Radians: Extended): Extended;{
圆周
:=
弧度
/ 2PI
}
4)
函数
DegToRad(const Degrees: Extended): Extended;
{
弧度
:=
度数
* PI / 180
}
5)
函数
DegToGrad(const Degrees: Extended): Extended;
6)
函数
DegToCycle(const Degrees: Extended): Extended;
7)
函数
GradToRad(const Grads: Extended): Extended;
{
弧度
:=
梯度
* PI / 200
}
8)
函数
GradToDeg(const Grads: Extended): Extended;
9)
函数
GradToCycle(const Grads: Extended): Extended;
10)
函数
CycleToRad(const Cycles: Extended): Extended; {
弧度
:=
圆周
* 2PI
}
11)
函数
CycleToDeg(const Cycles: Extended): Extended;
12)
函数
CycleToGrad(const Cycles: Extended): Extended;
三、
双曲线函数
1)
弧度
Cot(const X: Extended): Extended;
{
别名为
Cotan }
2)
函数
Sec(const X: Extended): Extended;
{
别名为
Secant }
3)
函数
Csc(const X: Extended): Extended;
{
别名为
Cosecant }
4)
函数
Cosh(const X: Extended): Extended;
5)
函数
Sinh(const X: Extended): Extended;
6)
函数
Tanh(const X: Extended): Extended;
7)
函数
CotH(const X: Extended): Extended;
8)
函数
SecH(const X: Extended): Extended;
9)
函数
CscH(const X: Extended): Extended;
10)
函数
ArcCot(const X: Extended): Extended;
{ IN: X <> 0 }
11)
函数
ArcSec(const X: Extended): Extended;
{ IN: X <> 0 }
12)
函数
ArcCsc(const X: Extended): Extended;
{ IN: X <> 0 }
13)
函数
ArcCosh(const X: Extended): Extended;
{ IN: X >= 1 }
14)
函数
ArcSinh(const X: Extended): Extended;
15)
函数
ArcTanh(const X: Extended): Extended;
{ IN: |X| <= 1 }
16)
函数
ArcCotH(const X: Extended): Extended;
{ IN: X <> 0 }
17)
函数
ArcSecH(const X: Extended): Extended;
{ IN: X <> 0 }
18)
函数
ArcCscH(const X: Extended): Extended;
{ IN: X <> 0 }
四、
对数函数
1)
函数
LnXP1(const X: Extended): Extended; { Ln(X + 1), accurate for X near zero }
2)
函数
Log10(const X: Extended): Extended;
{
基数为
10
的
X
对数
}
3)
函数
Log2(const X: Extended): Extended;
{
基数为
2
的
X
对数
}
4)
函数
LogN(const Base, X: Extended): Extended;
{
基数为
N
的
X
对数
}
五、
指数函数
1)
函数
IntPower(const Base: Extended; const Exponent: Integer): Extended register;
IntPower
:任意基数
Base
的
Exponent
整数幂。快
2)
函数
Power(const Base, Exponent: Extended): Extended;
Power
:任意基数的任意幂;
对于分指数或
|
指数
| > MaxInt
,
基数必须
> 0.
六、
各种例程
1)
过程
Frexp(const X: Extended; var Mantissa: Extended; var Exponent: Integer) register;
Frexp
:分离
X
的尾数和指数
2)
函数
Ldexp(const X: Extended; const P: Integer): Extended register;
Ldexp
:返回
X*2^P
3)
函数
Ceil(const X: Extended):Integer;
Ceil
:最小整数
>= X, |X| < MaxInt
4)
函数
Floor(const X: Extended): Integer;
Floor
:最大整数
<= X,
|X| < MaxInt
5)
函数
Poly(const X: Extended; const Coefficients: array of Double): Extended;