IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

<QtMath> - Generic Math Functions

The <QtMath> header file provides various math functions.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

<QtMath> - Generic Math Functions

  • Header: QtMath

  • Group: <QtMath> is part of funclists

Detailed Description

These functions are partly convenience definitions for basic math operations not available in the C or Standard Template Libraries.

The header also ensures some constants specified in POSIX, but not present in C++ standards (so absent from <math.h> on some platforms), are defined:

Constant

Description

M_E

The base of the natural logarithms, e = exp(1)

M_LOG2E

The base-two logarithm of e

M_LOG10E

The base-ten logarithm of e

M_LN2

The natural logarithm of two

M_LN10

The natural logarithm of ten

M_PI

The ratio of a circle's circumference to diameter, π

M_PI_2

Half M_PI, π / 2

M_PI_4

Quarter M_PI, π / 4

M_1_PI

The inverse of M_PI, 1 / π

M_2_PI

Twice the inverse of M_PI, 2 / π

M_2_SQRTPI

Two divided by the square root of pi, 2 / √π

M_SQRT2

The square root of two, √2

M_SQRT1_2

The square roof of half, 1 / √2

Function Documentation

 

auto qAcos(T v)

Returns the arccosine of v as an angle in radians. Arccosine is the inverse operation of cosine.

See Also

See also qAtan(), qAsin(), qCos()

auto qAsin(T v)

Returns the arcsine of v as an angle in radians. Arcsine is the inverse operation of sine.

See Also

See also qSin(), qAtan(), qAcos()

auto qAtan2(T1 y, T2 x)

Returns the arctangent of a point specified by the coordinates y and x. This function will return the angle (argument) of that point.

See Also

See also qAtan(), qHypot()

auto qAtan(T v)

Returns the arctangent of v as an angle in radians. Arctangent is the inverse operation of tangent.

See Also

See also qTan(), qAcos(), qAsin()

int qCeil(T v)

Returns the ceiling of the value v.

The ceiling is the smallest integer that is not less than v. For example, if v is 41.2, then the ceiling is 42.

See Also

See also qFloor()

auto qCos(T v)

Returns the cosine of an angle v in radians.

See Also

See also qSin(), qTan()

[constexpr, since 5.1] float qDegreesToRadians(float degrees)

This function converts the degrees in float to radians.

Example:

 
Sélectionnez
float degrees = 180.0f
float radians = qDegreesToRadians(degrees)

This function was introduced in Qt 5.1.

See Also

See also qRadiansToDegrees()

[constexpr, since 5.1] double qDegreesToRadians(double degrees)

This function converts the degrees in double to radians.

Example:

 
Sélectionnez
double degrees = 180.0
double radians = qDegreesToRadians(degrees)

This function was introduced in Qt 5.1.

See Also

See also qRadiansToDegrees()

[constexpr, since 6.0] long double qDegreesToRadians(long double degrees)

This function converts the degrees in double to radians.

This function was introduced in Qt 6.0.

See Also

See also qRadiansToDegrees()

auto qExp(T v)

Returns the exponential function of e to the power of v.

See Also

See also qLn()

auto qFabs(T v)

Returns the absolute value of v.

int qFloor(T v)

Returns the floor of the value v.

The floor is the largest integer that is not greater than v. For example, if v is 41.2, then the floor is 41.

See Also

See also qCeil()

[since 6.1] auto qHypot(F first, Fs... rest)

Returns the distance from origin in arbitrarily many dimensions

This is as for the two-argument and three-argument forms, supported by std::hypot(), but with as many numeric parameters as you care to pass to it. Uses first and each of the rest as coordinates, performing a calculation equivalent to squaring each, summing and returning the square root, save that underflow and overflow are avoided as far as possible.

This function was introduced in Qt 6.1.

See Also

See also qSqrt()

[since 6.1] auto qHypot(Tx x, Ty y)

This is an overloaded function.

Returns the distance of a point (x, y) from the origin (0, 0).

This is qSqrt(x * x + y * y), optimized. In particular, underflow and overflow may be avoided.

Accepts any mix of numeric types, returning the same floating-point type as std::hypot(). If either parameter is infinite, so is the result; otherwise, if either is a NaN, so is the result.

This function was introduced in Qt 6.1.

See Also

See also qSqrt(), qAtan2()

[since 6.1] auto qHypot(Tx x, Ty y, Tz z)

This is an overloaded function.

Returns the distance of a point (x, y, z) from the origin (0, 0, 0).

This is qSqrt(x * x + y * y + z * z), optimized where supported. In particular, underflow and overflow may be avoided.

Accepts any mix of numeric types, returning the same floating-point type as std::hypot(). If any parameter is infinite, so is the result; otherwise, if any is NaN, so is the result.

This function was introduced in Qt 6.1.

See Also

See also qSqrt()

auto qLn(T v)

Returns the natural logarithm of v. Natural logarithm uses base e.

See Also

See also qExp()

[constexpr, since 5.4] quint32 qNextPowerOfTwo(quint32 value)

This function returns the nearest power of two greater than value. For 0 it returns 1, and for values larger than or equal to 2^31 the result is undefined.

This function was introduced in Qt 5.4.

[constexpr, since 5.4] quint32 qNextPowerOfTwo(qint32 value)

This is an overloaded function.

This function returns the nearest power of two greater than value. For negative values the result is undefined.

This function was introduced in Qt 5.4.

[constexpr, since 5.4] quint64 qNextPowerOfTwo(quint64 value)

This function returns the nearest power of two greater than value. For 0 it returns 1, and for values larger than or equal to 2^63 the result is undefined.

This function was introduced in Qt 5.4.

[constexpr, since 5.4] quint64 qNextPowerOfTwo(qint64 value)

This is an overloaded function.

This function returns the nearest power of two greater than value. For negative values the result is undefined.

This function was introduced in Qt 5.4.

auto qPow(T1 x, T2 y)

Returns the value of x raised to the power of y. That is, x is the base and y is the exponent.

See Also

See also qSqrt()

[constexpr, since 5.1] float qRadiansToDegrees(float radians)

This function converts the radians in float to degrees.

Example:

 
Sélectionnez
float radians = float(M_PI)
float degrees = qRadiansToDegrees(radians)

This function was introduced in Qt 5.1.

See Also

See also qDegreesToRadians()

[constexpr, since 5.1] double qRadiansToDegrees(double radians)

This function converts the radians in double to degrees.

Example:

 
Sélectionnez
double radians = M_PI
double degrees = qRadiansToDegrees(radians)

This function was introduced in Qt 5.1.

See Also

See also qDegreesToRadians()

[constexpr, since 6.0] long double qRadiansToDegrees(long double radians)

This function converts the radians in double to degrees.

This function was introduced in Qt 6.0.

See Also

See also qDegreesToRadians()

auto qSin(T v)

Returns the sine of the angle v in radians.

See Also

See also qCos(), qTan()

auto qSqrt(T v)

Returns the square root of v. This function returns a NaN if v is a negative number.

See Also

See also qPow(), qHypot()

auto qTan(T v)

Returns the tangent of an angle v in radians.

See Also

See also qSin(), qCos()

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+