国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Delphi > 正文

Delphi Math里的基本函數,以及浮點數比較函數

2019-11-11 06:27:53
字體:
來源:轉載
供稿:網友

Delphi里的好東西太多,多到讓人覺得煩。這種感覺就是當年打游戲《英雄無敵3》,改了錢以后,有錢了每天都要造建筑,明明是好事,可是讓人覺得煩。

先記錄下來,以后再回來加強對Math單元的研究,不必再自己發明函數去比較浮點數了~

 

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 AValue, AMin, AMax: Integer): Integer; overload;function EnsureRange(const AValue, AMin, AMax: Int64): Int64; overload;function EnsureRange(const AValue, AMin, AMax: Double): Double; overload;

返回確保在某一范圍內的值。如果AValue<AMin,則返回AMin;如果AValue>AMax,則返回AMax;其返回值只能為Integer、Int64、Double類型的值。

 

5. InRange

function InRange(const AValue, AMin, AMax: Integer): Boolean; overload;function InRange(const AValue, AMin, AMax: Int64): Boolean; overload;function InRange(const AValue, AMin, AMax: Double): Boolean; overload;

用來判斷一個數是否在某一范圍內。如AMin<=AValue<=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 AValue: 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類中比較常用。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 陆川县| 独山县| 徐汇区| 凤阳县| 琼结县| 武平县| 平罗县| 平顶山市| 博客| 汾西县| 龙门县| 湘西| 桑日县| 宾阳县| 永顺县| 蒲江县| 六枝特区| 榆社县| 安吉县| 嘉义市| 延川县| 长海县| 游戏| 丹江口市| 突泉县| 建始县| 焦作市| 海晏县| 盖州市| 天峨县| 石城县| 沙河市| 逊克县| 来安县| 华蓥市| 湄潭县| 农安县| 鹤山市| 安化县| 洱源县| 临西县|