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

首頁(yè) > 編程 > Delphi > 正文

Delphi Math里的基本函數(shù),以及浮點(diǎn)數(shù)比較函數(shù)

2019-11-11 04:58:51
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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

先記錄下來(lái),以后再回來(lái)加強(qiáng)對(duì)Math單元的研究,不必再自己發(fā)明函數(shù)去比較浮點(diǎn)數(shù)了~

 

Ceil

function Ceil(const X: Extended):Integer;:按正無(wú)窮大方向四舍五入一個(gè)變量。例如:

Ceil(-2.8) = -2;  Ceil(2.8) = 3;  Ceil(-1.0) = -1;  

Floor

function Floor(const X: Extended): Integer;:按負(fù)無(wú)窮方向四舍五入一個(gè)變量。例如:

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兩個(gè)變量的關(guān)系。如果A<B,則返回值為-1;如果A=B,則返回值為0;如果A>B,則返回值為1;其中A、B只能為Integer、Int64、Single、Double、Extended表達(dá)式。

 

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;

返回確保在某一范圍內(nèi)的值。如果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;

用來(lái)判斷一個(gè)數(shù)是否在某一范圍內(nèi)。如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;

比較兩個(gè)數(shù)字表達(dá)式返回其中的較大者。其中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;

比較兩個(gè)數(shù)字表達(dá)式返回其中的較小者。其中A、B的類型為Integer、Int64、Single、Double、Extended中的一類。

 

7. Power、Round、RoundTo

Power

function Power(const Base, Exponent: Extended): Extended;:返回底數(shù)的任何次冪。其中base是底數(shù),Exponent是指數(shù)。

Round

function Round(X: Extended): Int64;:將實(shí)數(shù)四舍五入為整數(shù)。

RoundTo

type TRoundToRange = -37..37;function RoundTo(const AValue: Double; const ADigit: TRoundToRange): Double;:將實(shí)數(shù)按指定的ADigit來(lái)進(jìn)行四舍五入。

RoundTo(1234567,3) = 1234000;  RoundTo(1.234,-2) = 1.23;  RoundTo(1.235,-2) = 1.24;  

 

8.Trunc

function Trunc(X: Extended): Int64;:返回一個(gè)函數(shù)的整數(shù)部分。與Int函數(shù)相似。

 

以上介紹的幾個(gè)函數(shù)在Math類中比較常用。


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 綦江县| 孙吴县| 韶关市| 昂仁县| 盐城市| 阿拉善左旗| 泗洪县| 云阳县| 含山县| 宽城| 宾阳县| 叙永县| 武清区| 阳泉市| 霍林郭勒市| 大名县| 泽库县| 五家渠市| 泰顺县| 晋江市| 华亭县| 巴东县| 阜平县| 巧家县| 齐齐哈尔市| 历史| 娄烦县| 苍南县| 大同县| 银川市| 乳源| 米泉市| 丽江市| 安溪县| 五家渠市| 绥阳县| 大同县| 九龙县| 龙泉市| 长寿区| 嵩明县|