Basic functions in Delphi math, and floating-point comparison functions

Source: Internet
Author: User
Tags rounds

Source: Basic Functions in Delphi math, and floating-point comparison functions

There are too many good things in Delphi, so much so that people feel bored. This feeling is playing the game "Heroes Invincible 3", change the money, the rich every day to build buildings, obviously is good, but let people feel bored.

Record it and come back later to strengthen the study of the math unit, no longer have to invent the function to compare the floating point number ~

1.Ceil

function ceil (const x:extended): Integer;: Rounds a variable by the positive infinity direction. For example:

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

3.Floor

function floor (const x:extended): Integer;: Rounds a variable in negative infinity direction. For example:

Floor (-2.8) =-3;  Floor (2.82;  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;

Compare the relationships of A and B two variables. If a<b, the return value is-1, if a=b, the return value is 0, and if a>b, the return value is 1, where a and B can be integers, Int64, single, Double, and extended expressions.

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;

Returns a value that is guaranteed to be within a range. Returns AMin if avalue<amin, or AMax if Avalue>amax, whose return value can only be an integer, Int64, double type.

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;

Used to determine whether a number is within a certain range. Returns True if Amin<=avalue<=amax, otherwise false is returned.

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;

Compares two numeric expressions to return the larger of them. Where A and B are of type 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;

Compares two numeric expressions to return the smaller ones. Where A and B are of type Integer, Int64, Single, Double, extended.

7. Power, Round, roundto

Power

function Power (const Base, exponent:extended): Extended;: Returns any power to a base. Where base is the radix, exponent is the exponent.

Round

function Round (x:extended): Int64;: Rounding a real number to an integer.

Roundto

Type troundtorange = -37..37;

function roundto (const avalue:double; const adigit:troundtorange): Double;: The real number is rounded by the specified adigit.

Roundto (1234567,31234000;  Roundto (1.234,-21.23;  Roundto (1.235,-21.24;  

8.Trunc

function Trunc (x:extended): Int64;: Returns the integer part of a function. is similar to the INT function.

Several of the functions described above are commonly used in the math class.

Reference:

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

Basic functions in Delphi math, and floating-point comparison functions (RPM)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.