std.math

Function Description

The math package provides common functions such as mathematical operations, constant definition, and floating-point number processing.

The following capabilities are included:

  1. Definition of scientific constants and type constants
  2. Judgment and normalization of floating-point numbers
  3. Common bitwise operations
  4. General mathematical functions, such as absolute value, trigonometric function, exponent, and logarithmic calculation
  5. Greatest common divisor and least common multiple

API List

Function

NameDescription
abs(Float16)Obtains the absolute value of a half-precision floating-point number through calculation.
abs(Float32)Obtains the absolute value of a single-precision floating-point number through calculation.
abs(Float64)Obtains the absolute value of a double-precision floating-point number through calculation.
abs(Int16)Obtains the absolute value of a 16-bit signed integer through calculation.
abs(Int32)Obtains the absolute value of a 32-bit signed integer through calculation.
abs(Int64)Obtains the absolute value of a 64-bit signed integer through calculation.
abs(Int8)Obtains the absolute value of an 8-bit signed integer through calculation.
acos(Float16)Obtains the arc cosine function value of a half-precision floating-point number through calculation, in radians.
acos(Float32)Obtains the arc cosine function value of a single-precision floating-point number through calculation, in radians.
acos(Float64)Obtains the arc cosine function value of a double-precision floating-point number through calculation, in radians.
acosh(Float16)Obtains the inverse hyperbolic cosine function value of a half-precision floating-point number through calculation.
acosh(Float32)Obtains the inverse hyperbolic cosine function value of a single-precision floating-point number through calculation.
acosh(Float64)Obtains the inverse hyperbolic cosine function value of a double-precision floating-point number through calculation.
asin(Float16)Obtains the arc sine function value of a half-precision floating-point number through calculation, in radians.
asin(Float32)Obtains the arc sine function value of a single-precision floating-point number through calculation, in radians.
asin(Float64)Obtains the arc sine function value of a double-precision floating-point number through calculation, in radians.
asinh(Float16)Obtains the inverse hyperbolic sine function value of a half-precision floating-point number through calculation.
asinh(Float32)Obtains the inverse hyperbolic sine function value of a single-precision floating-point number through calculation.
asinh(Float64)Obtains the inverse hyperbolic sine function value of a double-precision floating-point number through calculation.
atan(Float16)Obtains the arc tangent function value of a half-precision floating-point number through calculation, in radians.
atan(Float32)Obtains the arc tangent function value of a single-precision floating-point number through calculation, in radians.
atan(Float64)Obtains the arc tangent function value of a double-precision floating-point number through calculation, in radians.
atan2(Float16, Float16)Obtains the arc tangent function value of two half-precision floating-point numbers through calculation, in radians.
atan2(Float32, Float32)Obtains the arc tangent function value of two single-precision floating-point numbers through calculation, in radians.
atan2(Float64, Float64)Obtains the arc tangent function value of two double-precision floating-point numbers through calculation, in radians.
atanh(Float16)Obtains the inverse hyperbolic tangent function value of a half-precision floating-point number through calculation.
atanh(Float32)Obtains the inverse hyperbolic tangent function value of a single-precision floating-point number through calculation.
atanh(Float64)Obtains the inverse hyperbolic tangent function value of a double-precision floating-point number through calculation.
cbrt(Float16)Obtains the cube root of a half-precision floating-point number through calculation.
cbrt(Float32)Obtains the cube root of a single-precision floating-point number through calculation.
cbrt(Float64)Obtains the cube root of a double-precision floating-point number through calculation.
ceil(Float16)Obtains the rounded-up value of a half-precision floating-point number through calculation.
ceil(Float32)Obtains the rounded-up value of a single-precision floating-point number through calculation.
ceil(Float64)Obtains the rounded-up value of a double-precision floating-point number through calculation.
checkedAbs(Int16)Checks and obtains the absolute value of a 16-bit signed integer through calculation. If the input parameter is the minimum value of the 16-bit signed integer, None is returned. Otherwise, Some(abs(x)) is returned.
checkedAbs(Int32)Checks and obtains the absolute value of a 32-bit signed integer through calculation. If the input parameter is the minimum value of the 32-bit signed integer, None is returned. Otherwise, Some(abs(x)) is returned.
checkedAbs(Int64)Checks and obtains the absolute value of a 64-bit signed integer through calculation. If the input parameter is the minimum value of the 64-bit signed integer, None is returned. Otherwise, Some(abs(x)) is returned.
checkedAbs(Int8)Checks and obtains the absolute value of an 8-bit signed integer through calculation. If the input parameter is the minimum value of the 8-bit signed integer, None is returned. Otherwise, Some(abs(x)) is returned.
clamp(Float16, Float16, Float16)Obtains the value of a floating-point number to which the clamp function with a given range is applied. If the floating-point number is within the range, the floating-point number is returned. If the floating-point number is less than the minimum value in the range, the minimum value is returned. If the floating-point number is greater than the maximum value in the range, the maximum value is returned. If the floating-point number is NaN, NaN is returned.
clamp(Float32, Float32, Float32)Obtains the value of a floating-point number to which the clamp function with a given range is applied. If the floating-point number is within the range, the floating-point number is returned. If the floating-point number is less than the minimum value in the range, the minimum value is returned. If the floating-point number is greater than the maximum value in the range, the maximum value is returned. If the floating-point number is NaN, NaN is returned.
clamp(Float64, Float64, Float64)Obtains the value of a floating-point number to which the clamp function with a given range is applied. If the floating-point number is within the range, the floating-point number is returned. If the floating-point number is less than the minimum value in the range, the minimum value is returned. If the floating-point number is greater than the maximum value in the range, the maximum value is returned. If the floating-point number is NaN, NaN is returned.
cos(Float16)Obtains the cosine function value of a half-precision floating-point number through calculation, in radians.
cos(Float32)Obtains the cosine function value of a single-precision floating-point number through calculation, in radians.
cos(Float64)Obtains the cosine function value of a double-precision floating-point number through calculation, in radians.
cosh(Float16)Obtains the hyperbolic cosine function value of a half-precision floating-point number through calculation.
cosh(Float32)Obtains the hyperbolic cosine function value of a single-precision floating-point number through calculation.
cosh(Float64)Obtains the hyperbolic cosine function value of a double-precision floating-point number through calculation.
countOne(Int16) (deprecated)Obtains the number of bits of 1s in the binary expression of a 16-bit integer.
countOne(Int32) (deprecated)Obtains the number of bits of 1s in the binary expression of a 32-bit integer.
countOne(Int64) (deprecated)Obtains the number of bits of 1s in the binary expression of a 64-bit integer.
countOne(Int8) (deprecated)Obtains the number of bits of 1s in the binary expression of an 8-bit integer.
countOne(UInt16) (deprecated)Obtains the number of bits of 1s in the binary expression of a 16-bit unsigned integer.
countOne(UInt32) (deprecated)Obtains the number of bits of 1s in the binary expression of a 32-bit unsigned integer.
countOne(UInt64) (deprecated)Obtains the number of bits of 1s in the binary expression of a 64-bit unsigned integer.
countOne(UInt8) (deprecated)Obtains the number of bits of 1s in the binary expression of an 8-bit unsigned integer.
countOnes(Int16)Obtains the number of bits of 1s in the binary expression of a 16-bit integer.
countOnes(Int32)Obtains the number of bits of 1s in the binary expression of a 32-bit integer.
countOnes(Int64)Obtains the number of bits of 1s in the binary expression of a 64-bit integer.
countOnes(Int8)Obtains the number of bits of 1s in the binary expression of an 8-bit integer.
countOnes(UInt16)Obtains the number of bits of 1s in the binary expression of a 16-bit unsigned integer.
countOnes(UInt32)Obtains the number of bits of 1s in the binary expression of a 32-bit unsigned integer.
countOnes(UInt64)Obtains the number of bits of 1s in the binary expression of a 64-bit unsigned integer.
countOnes(UInt8)Obtains the number of bits of 1s in the binary expression of an 8-bit unsigned integer.
erf(Float16)Obtains the error value of a half-precision floating-point number through calculation.
erf(Float32)Obtains the error value of a single-precision floating-point number through calculation.
erf(Float64)Obtains the error value of a double-precision floating-point number through calculation.
exp(Float16)Obtains the natural constant e raised to the power of x.
exp(Float32)Obtains the natural constant e raised to the power of x.
exp(Float64)Obtains the natural constant e raised to the power of x.
exp2(Float16)Obtains 2 raised to the power of x.
exp2(Float32)Obtains 2 raised to the power of x.
exp2(Float64)Obtains 2 raised to the power of x.
floor(Float16)Obtains the rounded-down value of a floating-point number through calculation.
floor(Float32)Obtains the rounded-down value of a floating-point number through calculation.
floor(Float64)Obtains the rounded-down value of a floating-point number through calculation.
fmod(Float16, Float16)Obtains the remainder of the division of two half-precision floating-point numbers through calculation.
fmod(Float32, Float32)Obtains the remainder of the division of two single-precision floating-point numbers through calculation.
fmod(Float64, Float64)Obtains the remainder of the division of two double-precision floating-point numbers through calculation.
gamma(Float16)Obtains the gamma value of a floating-point number through calculation.
gamma(Float32)Obtains the gamma value of a floating-point number through calculation.
gamma(Float64)Obtains the gamma value of a floating-point number through calculation.
gcd(Int16, Int16)Obtains the greatest common divisor of two 16-bit signed integers through calculation.
gcd(Int32, Int32)Obtains the greatest common divisor of two 32-bit signed integers through calculation.
gcd(Int64, Int64)Obtains the greatest common divisor of two 64-bit signed integers through calculation.
gcd(Int8, Int8)Obtains the greatest common divisor of two 8-bit signed integers through calculation.
gcd(UInt16, UInt16)Obtains the greatest common divisor of two 16-bit unsigned integers through calculation.
gcd(UInt32, UInt32)Obtains the greatest common divisor of two 32-bit unsigned integers through calculation.
gcd(UInt64, UInt64)Obtains the greatest common divisor of two 64-bit unsigned integers through calculation.
gcd(UInt8, UInt8)Obtains the greatest common divisor of two 8-bit unsigned integers through calculation.
lcm(Int16, Int16)Obtains the non-negative least common multiple of two 16-bit signed integers through calculation. The value 0 is returned only when any input parameter is 0.
lcm(Int32, Int32)Obtains the non-negative least common multiple of two 32-bit signed integers through calculation. The value 0 is returned only when any input parameter is 0.
lcm(Int64, Int64)Obtains the non-negative least common multiple of two 64-bit signed integers through calculation. The value 0 is returned only when any input parameter is 0.
lcm(Int8, Int8)Obtains the non-negative least common multiple of two 8-bit signed integers through calculation. The value 0 is returned only when any input parameter is 0.
lcm(UInt16, UInt16)Obtains the non-negative least common multiple of two 16-bit unsigned integers through calculation. The value 0 is returned only when any input parameter is 0.
lcm(UInt32, UInt32)Obtains the non-negative least common multiple of two 32-bit unsigned integers through calculation. The value 0 is returned only when any input parameter is 0.
lcm(UInt64, UInt64)Obtains the non-negative least common multiple of two 64-bit unsigned integers through calculation. The value 0 is returned only when any input parameter is 0.
lcm(UInt8, UInt8)Obtains the non-negative least common multiple of two 8-bit unsigned integers through calculation. The value 0 is returned only when any input parameter is 0.
leadingZeros(Int16)Obtains the number of consecutive 0s starting from the most significant bit in the binary expression of a 16-bit signed integer. If the most significant bit is not 0, the value 0 is returned.
leadingZeros(Int32)Obtains the number of consecutive 0s starting from the most significant bit in the binary expression of a 32-bit signed integer. If the most significant bit is not 0, the value 0 is returned.
leadingZeros(Int64)Obtains the number of consecutive 0s starting from the most significant bit in the binary expression of a 64-bit signed integer. If the most significant bit is not 0, the value 0 is returned.
leadingZeros(Int8)Obtains the number of consecutive 0s starting from the most significant bit (including signs) in the binary expression of an 8-bit signed integer. If the most significant bit is not 0, the value 0 is returned.
leadingZeros(UInt16)Obtains the number of consecutive 0s starting from the most significant bit in the binary expression of a 16-bit unsigned integer.
leadingZeros(UInt32)Obtains the number of consecutive 0s starting from the most significant bit in the binary expression of a 32-bit unsigned integer.
leadingZeros(UInt64)Obtains the number of consecutive 0s starting from the most significant bit in the binary expression of a 64-bit unsigned integer.
leadingZeros(UInt8)Obtains the number of consecutive 0s starting from the most significant bit in the binary expression of an 8-bit unsigned integer.
log(Float16)Obtains the logarithm of x with base e.
log(Float32)Obtains the logarithm of x with base e.
log(Float64)Obtains the logarithm of x with base e.
log10(Float16)Obtains the logarithm of x with base 10.
log10(Float32)Obtains the logarithm of x with base 10.
log10(Float64)Obtains the logarithm of x with base 10.
log2(Float16)Obtains the logarithm of x with base 2.
log2(Float32)Obtains the logarithm of x with base 2.
log2(Float64)Obtains the logarithm of x with base 2.
logBase(Float16, Float16)Obtains the logarithm of x with base base.
logBase(Float32, Float32)Obtains the logarithm of x with base base.
logBase(Float64, Float64)Obtains the logarithm of x with base base.
pow(Float32, Float32)Obtains the floating-point number base raised to the power of exponent.
pow(Float32, Int32)Obtains the floating-point number base raised to the power of exponent.
pow(Float64, Float64)Obtains the floating-point number base raised to the power of exponent.
pow(Float64, Int64)Obtains the floating-point number base raised to the power of exponent.
reverse(UInt16)Obtains the number after bitwise inversion of an unsigned integer.
reverse(UInt32)Obtains the number after bitwise inversion of an unsigned integer.
reverse(UInt64)Obtains the number after bitwise inversion of an unsigned integer.
reverse(UInt8)Obtains the number after bitwise inversion of an unsigned integer.
rotate(Int16, Int8)Obtains the result of bitwise rotation of an integer.
rotate(Int32, Int8)Obtains the result of bitwise rotation of an integer.
rotate(Int64, Int8)Obtains the result of bitwise rotation of an integer.
rotate(Int8, Int8)Obtains the result of bitwise rotation of an integer.
rotate(UInt16, Int8)Obtains the result of bitwise rotation of an integer.
rotate(UInt32, Int8)Obtains the result of bitwise rotation of an integer.
rotate(UInt64, Int8)Obtains the result of bitwise rotation of an integer.
rotate(UInt8, Int8)Obtains the result of bitwise rotation of an integer.
round(Float16)Obtains the rounded-off value of a floating-point number through calculation based on the round-off rule in IEEE-754.
round(Float32)Obtains the rounded-off value of a floating-point number through calculation based on the round-off rule in IEEE-754.
round(Float64)Obtains the rounded-off value of a floating-point number through calculation based on the round-off rule in IEEE-754.
sin(Float16)Obtains the sine function value of a half-precision floating-point number through calculation, in radians.
sin(Float32)Obtains the sine function value of a single-precision floating-point number through calculation, in radians.
sin(Float64)Obtains the sine function value of a double-precision floating-point number through calculation, in radians.
sinh(Float16)Obtains the hyperbolic sine function value of a half-precision floating-point number through calculation.
sinh(Float32)Obtains the hyperbolic sine function value of a single-precision floating-point number through calculation.
sinh(Float64)Obtains the hyperbolic sine function value of a double-precision floating-point number through calculation.
sqrt(Float16)Obtains the arithmetic square root of a floating-point number through calculation.
sqrt(Float32)Obtains the arithmetic square root of a floating-point number through calculation.
sqrt(Float64)Obtains the arithmetic square root of a floating-point number through calculation.
tan(Float16)Obtains the tangent function value of a half-precision floating-point number through calculation, in radians.
tan(Float32)Obtains the tangent function value of a single-precision floating-point number through calculation, in radians.
tan(Float64)Obtains the tangent function value of a double-precision floating-point number through calculation, in radians.
tanh(Float16)Obtains the hyperbolic tangent function value of a half-precision floating-point number through calculation.
tanh(Float32)Obtains the hyperbolic tangent function value of a single-precision floating-point number through calculation.
tanh(Float64)Obtains the hyperbolic tangent function value of a double-precision floating-point number through calculation.
trailingZeros(Int16)Obtains the number of consecutive 0s starting from the least significant bit in the binary expression of a 16-bit signed integer. If the least significant bit is not 0, the value 0 is returned.
trailingZeros(Int32)Obtains the number of consecutive 0s starting from the least significant bit in the binary expression of a 32-bit signed integer. If the least significant bit is not 0, the value 0 is returned.
trailingZeros(Int64)Obtains the number of consecutive 0s starting from the least significant bit in the binary expression of a 64-bit signed integer. If the least significant bit is not 0, the value 0 is returned.
trailingZeros(Int8)Obtains the number of consecutive 0s starting from the least significant bit in the binary expression of a 16-bit signed integer. If the least significant bit is not 0, the value 0 is returned.
trailingZeros(UInt16)Obtains the number of consecutive 0s starting from the least significant bit in the binary expression of a 16-bit unsigned integer. If the least significant bit is not 0, the value 0 is returned.
trailingZeros(UInt32)Obtains the number of consecutive 0s starting from the least significant bit in the binary expression of a 32-bit unsigned integer. If the least significant bit is not 0, the value 0 is returned.
trailingZeros(UInt64)Obtains the number of consecutive 0s starting from the least significant bit in the binary expression of a 64-bit unsigned integer. If the least significant bit is not 0, the value 0 is returned.
trailingZeros(UInt8)Obtains the number of consecutive 0s starting from the least significant bit in the binary expression of an 8-bit unsigned integer. If the least significant bit is not 0, the value 0 is returned.
trunc(Float16)Obtains the value after truncation of a floating-point number through calculation.
trunc(Float32)Obtains the value after truncation of a floating-point number through calculation.
trunc(Float64)Obtains the value after truncation of a floating-point number through calculation.

Interface

NameDescription
FloatingPoint<T>Provides methods related to floating-point numbers.
Integer<T>Provides methods related to integer types.
MathExtension (deprecated)Specifies an auxiliary API for exporting the values of the PI and E properties with floating-point precision.
MaxMinValue<T>Provides methods for obtaining the maximum and minimum values.
Number<T>Provides methods related to numeric types.

Enumeration

EnumerationDescription
RoundingModeSpecifies the enumeration class of rounding rules, including six rounding rules. In addition to the five rounding rules of floating-point numbers specified in IEEE 754, the most commonly used rounding off rule is provided.