Delphi数学常用操作函数一
2013-02-17 09:02
176 查看
1.Abs
function Abs(X);:返回指定数值的绝对值。例如:
2. Ceil、Floor
Ceil
function Ceil(const X: Extended):Integer;:按正无穷大方向四舍五入一个变量。例如:
Floor
function Floor(const X: Extended): Integer;:按负无穷方向四舍五入一个变量。例如:
3. CompareValue
function CompareValue(const A, B: Integer): TValueRelationship; overload;
function CompareValue(const A, B: Int64): TValueRelationship; overload;
function CompareValue(const A, B: Single; Epsilon: Single = 0): TValueRelationship; overload;
function CompareValue(const A, B: Double; Epsilon: Double = 0): TValueRelationship; overload;
function CompareValue(const A, B: Extended; Epsilon: Extended = 0): TValueRelationship; overload;
比较A、B两个变量的关系。如果A<B,则返回值为-1;如果A=B,则返回值为0;如果A>B,则返回值为1;其中A、B只能为Integer、Int64、Single、Double、Extended表达式。
4. EnsureRange
function EnsureRange(const ***alue, AMin, AMax: Integer): Integer; overload;
function EnsureRange(const ***alue, AMin, AMax: Int64): Int64; overload;
function EnsureRange(const ***alue, AMin, AMax: Double): Double; overload;
返回确保在某一范围内的值。如果***alue<AMin,则返回AMin;如果***alue>AMax,则返回AMax;其返回值只能为Integer、Int64、Double类型的值。
5. InRange
function InRange(const ***alue, AMin, AMax: Integer): Boolean; overload;
function InRange(const ***alue, AMin, AMax: Int64): Boolean; overload;
function InRange(const ***alue, AMin, AMax: Double): Boolean; overload;
用来判断一个数是否在某一范围内。如AMin<=***alue<=AMax,则返回True;否则则返回False。
6. Max、Min
Max
function Max(A,B: Integer): Integer; overload;
function Max(A,B: Int64): Int64; overload;
function Max(A,B: Single): Single; overload;
function Max(A,B: Double): Double; overload;
function Max(A,B: Extended): Extended; overload;
比较两个数字表达式返回其中的较大者。其中A、B的类型为Integer、Int64、Single、Double、Extended中的一类。
Min
function Min(A,B: Integer): Integer; overload;
function Min(A,B: Int64): Int64; overload;
function Min(A,B: Single): Single; overload;
function Min(A,B: Double): Double; overload;
function Min(A,B: Extended): Extended; overload;
比较两个数字表达式返回其中的较小者。其中A、B的类型为Integer、Int64、Single、Double、Extended中的一类。
7. Power、Round、RoundTo
Power
function Power(const Base, Exponent: Extended): Extended;:返回底数的任何次幂。其中base是底数,Exponent是指数。
Round
function Round(X: Extended): Int64;:将实数四舍五入为整数。
RoundTo
type TRoundToRange = -37..37;
function RoundTo(const ***alue: Double; const ADigit: TRoundToRange): Double;:将实数按指定的ADigit来进行四舍五入。
8.Trunc
function Trunc(X: Extended): Int64;:返回一个函数的整数部分。与Int函数相似。
以上介绍的几个函数在Math类中比较常用。
function Abs(X);:返回指定数值的绝对值。例如:
Abs(-15); //结果为15
2. Ceil、Floor
Ceil
function Ceil(const X: Extended):Integer;:按正无穷大方向四舍五入一个变量。例如:
Ceil(-2.8) = -2; Ceil(2.8) = 3; Ceil(-1.0) = -1;
Floor
function Floor(const X: Extended): Integer;:按负无穷方向四舍五入一个变量。例如:
Floor(-2.8) = -3; Floor(2.8) = 2; Floor(-1.0) = -1;
3. CompareValue
function CompareValue(const A, B: Integer): TValueRelationship; overload;
function CompareValue(const A, B: Int64): TValueRelationship; overload;
function CompareValue(const A, B: Single; Epsilon: Single = 0): TValueRelationship; overload;
function CompareValue(const A, B: Double; Epsilon: Double = 0): TValueRelationship; overload;
function CompareValue(const A, B: Extended; Epsilon: Extended = 0): TValueRelationship; overload;
比较A、B两个变量的关系。如果A<B,则返回值为-1;如果A=B,则返回值为0;如果A>B,则返回值为1;其中A、B只能为Integer、Int64、Single、Double、Extended表达式。
4. EnsureRange
function EnsureRange(const ***alue, AMin, AMax: Integer): Integer; overload;
function EnsureRange(const ***alue, AMin, AMax: Int64): Int64; overload;
function EnsureRange(const ***alue, AMin, AMax: Double): Double; overload;
返回确保在某一范围内的值。如果***alue<AMin,则返回AMin;如果***alue>AMax,则返回AMax;其返回值只能为Integer、Int64、Double类型的值。
5. InRange
function InRange(const ***alue, AMin, AMax: Integer): Boolean; overload;
function InRange(const ***alue, AMin, AMax: Int64): Boolean; overload;
function InRange(const ***alue, AMin, AMax: Double): Boolean; overload;
用来判断一个数是否在某一范围内。如AMin<=***alue<=AMax,则返回True;否则则返回False。
6. Max、Min
Max
function Max(A,B: Integer): Integer; overload;
function Max(A,B: Int64): Int64; overload;
function Max(A,B: Single): Single; overload;
function Max(A,B: Double): Double; overload;
function Max(A,B: Extended): Extended; overload;
比较两个数字表达式返回其中的较大者。其中A、B的类型为Integer、Int64、Single、Double、Extended中的一类。
Min
function Min(A,B: Integer): Integer; overload;
function Min(A,B: Int64): Int64; overload;
function Min(A,B: Single): Single; overload;
function Min(A,B: Double): Double; overload;
function Min(A,B: Extended): Extended; overload;
比较两个数字表达式返回其中的较小者。其中A、B的类型为Integer、Int64、Single、Double、Extended中的一类。
7. Power、Round、RoundTo
Power
function Power(const Base, Exponent: Extended): Extended;:返回底数的任何次幂。其中base是底数,Exponent是指数。
Round
function Round(X: Extended): Int64;:将实数四舍五入为整数。
RoundTo
type TRoundToRange = -37..37;
function RoundTo(const ***alue: Double; const ADigit: TRoundToRange): Double;:将实数按指定的ADigit来进行四舍五入。
RoundTo(1234567,3) = 1234000; RoundTo(1.234,-2) = 1.23; RoundTo(1.235,-2) = 1.24;
8.Trunc
function Trunc(X: Extended): Int64;:返回一个函数的整数部分。与Int函数相似。
以上介绍的几个函数在Math类中比较常用。
相关文章推荐
- Delphi数学常用操作函数二
- Delphi数学常用操作函数二
- JS常用数字、字符串操作函数总结
- Python常用时间操作总结【取得当前时间、时间函数、应用等】
- mysql常用字符串操作函数大全,以及实例
- 标准I/O常用函数以及Linux文件夹操作函数
- WinCE下的非常用字符串操作函数
- PHP常用的文件操作函数集锦
- C API操作mysql数据库常用的函数及介绍(全)
- Python中常用操作字符串的函数与方法总结
- PHP常用字符串操作函数实例总结(trim、nl2br、addcslashes、uudecode、md5等)
- Python中常用操作字符串的函数与方法总结
- C文件操作常用函数
- js操作url的常用函数
- java中关于时间日期操作的常用函数
- 常用函数公式及操作技巧系列文章【共十篇】
- PHP常用文件操作函数和简单实例分析
- Oracle常用操作与函数
- Bash中关于日期时间操作的常用自定义函数
- MySQL存储过程常用的函数(字符串类型操作,数学类,日期时间类)