日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Delphi Math里的基本函数,以及浮点数比较函数(转)

發(fā)布時(shí)間:2024/1/17 编程问答 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Delphi Math里的基本函数,以及浮点数比较函数(转) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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

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

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

?

1.Ceil

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

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

?

3.Floor

function Floor(const X: Extended): Integer;:按負(fù)無窮方向四舍五入一個(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;

用來判斷一個(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來進(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類中比較常用。

?

參考:

http://blog.csdn.net/kimifdw/article/details/8582725

?

轉(zhuǎn)載于:https://www.cnblogs.com/LittleTiger/p/4615349.html

總結(jié)

以上是生活随笔為你收集整理的Delphi Math里的基本函数,以及浮点数比较函数(转)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。