std.math

Function Overview

The math package provides common mathematical operations, constant definitions, floating-point number handling, and other functionalities.

It includes the following capabilities:

  1. Scientific constants and type constant definitions
  2. Floating-point number judgment and normalization
  3. Common bitwise operations
  4. General mathematical functions such as absolute value, trigonometric functions, exponential and logarithmic calculations
  5. Greatest common divisor and least common multiple

API List

Functions

Function Name Description
abs(Float16) Calculates the absolute value of a half-precision floating-point number.
abs(Float32) Calculates the absolute value of a single-precision floating-point number.
abs(Float64) Calculates the absolute value of a double-precision floating-point number.
abs(Int16) Calculates the absolute value of a 16-bit signed integer.
abs(Int32) Calculates the absolute value of a 32-bit signed integer.
abs(Int64) Calculates the absolute value of a 64-bit signed integer.
abs(Int8) Calculates the absolute value of an 8-bit signed integer.
acos(Float16) Calculates the arccosine of a half-precision floating-point number in radians.
acos(Float32) Calculates the arccosine of a single-precision floating-point number in radians.
acos(Float64) Calculates the arccosine of a double-precision floating-point number in radians.
acosh(Float16) Calculates the inverse hyperbolic cosine of a half-precision floating-point number.
acosh(Float32) Calculates the inverse hyperbolic cosine of a single-precision floating-point number.
acosh(Float64) Calculates the inverse hyperbolic cosine of a double-precision floating-point number.
asin(Float16) Calculates the arcsine of a half-precision floating-point number in radians.
asin(Float32) Calculates the arcsine of a single-precision floating-point number in radians.
asin(Float64) Calculates the arcsine of a double-precision floating-point number in radians.
asinh(Float16) Calculates the inverse hyperbolic sine of a half-precision floating-point number.
asinh(Float32) Calculates the inverse hyperbolic sine of a single-precision floating-point number.
asinh(Float64) Calculates the inverse hyperbolic sine of a double-precision floating-point number.
atan(Float16) Calculates the arctangent of a half-precision floating-point number in radians.
atan(Float32) Calculates the arctangent of a single-precision floating-point number in radians.
atan(Float64) Calculates the arctangent of a double-precision floating-point number in radians.
atan2(Float16, Float16) Calculates the arctangent of two half-precision floating-point numbers in radians.
atan2(Float32, Float32) Calculates the arctangent of two single-precision floating-point numbers in radians.
atan2(Float64, Float64) Calculates the arctangent of two double-precision floating-point numbers in radians.
atanh(Float16) Calculates the inverse hyperbolic tangent of a half-precision floating-point number.
atanh(Float32) Calculates the inverse hyperbolic tangent of a single-precision floating-point number.
atanh(Float64) Calculates the inverse hyperbolic tangent of a double-precision floating-point number.
cbrt(Float16) Calculates the cube root of a half-precision floating-point number.
cbrt(Float32) Calculates the cube root of a single-precision floating-point number.
cbrt(Float64) Calculates the cube root of a double-precision floating-point number.
ceil(Float16) Rounds a half-precision floating-point number up to the nearest integer.
ceil(Float32) Rounds a single-precision floating-point number up to the nearest integer.
ceil(Float64) Rounds a double-precision floating-point number up to the nearest integer.
checkedAbs(Int16) Checks and calculates the absolute value of a 16-bit signed integer. Returns None if the input is the minimum value of a 16-bit signed integer; otherwise returns Some(abs(x)).
checkedAbs(Int32) Checks and calculates the absolute value of a 32-bit signed integer. Returns None if the input is the minimum value of a 32-bit signed integer; otherwise returns Some(abs(x)).
checkedAbs(Int64) Checks and calculates the absolute value of a 64-bit signed integer. Returns None if the input is the minimum value of a 64-bit signed integer; otherwise returns Some(abs(x)).
checkedAbs(Int8) Checks and calculates the absolute value of an 8-bit signed integer. Returns None if the input is the minimum value of an 8-bit signed integer; otherwise returns Some(abs(x)).
clamp(Float16, Float16, Float16) Clamps a floating-point number within a specified range. Returns the number if it's within the range, the minimum value if below, the maximum value if above, or NaN if the input is NaN.
clamp(Float32, Float32, Float32) Clamps a floating-point number within a specified range. Returns the number if it's within the range, the minimum value if below, the maximum value if above, or NaN if the input is NaN.
clamp(Float64, Float64, Float64) Clamps a floating-point number within a specified range. Returns the number if it's within the range, the minimum value if below, the maximum value if above, or NaN if the input is NaN.
cos(Float16) Calculates the cosine of a half-precision floating-point number (input in radians).
cos(Float32) Calculates the cosine of a single-precision floating-point number (input in radians).
cos(Float64) Calculates the cosine of a double-precision floating-point number (input in radians).
cosh(Float16) Calculates the hyperbolic cosine of a half-precision floating-point number.
cosh(Float32) Calculates the hyperbolic cosine of a single-precision floating-point number.
cosh(Float64) Calculates the hyperbolic cosine of a double-precision floating-point number.
countOne(Int16) (deprecated) Counts the number of 1 bits in the binary representation of a 16-bit integer.
countOne(Int32) (deprecated) Counts the number of 1 bits in the binary representation of a 32-bit integer.
countOne(Int64) (deprecated) Counts the number of 1 bits in the binary representation of a 64-bit integer.
countOne(Int8) (deprecated) Counts the number of 1 bits in the binary representation of an 8-bit integer.
countOne(UInt16) (deprecated) Counts the number of 1 bits in the binary representation of a 16-bit unsigned integer.
countOne(UInt32) (deprecated) Counts the number of 1 bits in the binary representation of a 32-bit unsigned integer.
countOne(UInt64) (deprecated) Counts the number of 1 bits in the binary representation of a 64-bit unsigned integer.
countOne(UInt8) (deprecated) Counts the number of 1 bits in the binary representation of an 8-bit unsigned integer.
countOnes(Int16) Counts the number of 1 bits in the binary representation of a 16-bit integer.
countOnes(Int32) Counts the number of 1 bits in the binary representation of a 32-bit integer.
countOnes(Int64) Counts the number of 1 bits in the binary representation of a 64-bit integer.
countOnes(Int8) Counts the number of 1 bits in the binary representation of an 8-bit integer.
countOnes(UInt16) Counts the number of 1 bits in the binary representation of a 16-bit unsigned integer.
countOnes(UInt32) Counts the number of 1 bits in the binary representation of a 32-bit unsigned integer.
countOnes(UInt64) Counts the number of 1 bits in the binary representation of a 64-bit unsigned integer.
countOnes(UInt8) Counts the number of 1 bits in the binary representation of an 8-bit unsigned integer.
erf(Float16) Calculates the error function value of a half-precision floating-point number.
erf(Float32) Calculates the error function value of a single-precision floating-point number.
erf(Float64) Calculates the error function value of a double-precision floating-point number.
exp(Float16) Calculates e raised to the power of x.
exp(Float32) Calculates e raised to the power of x.
exp(Float64) Calculates e raised to the power of x.
exp2(Float16) Calculates 2 raised to the power of x.
exp2(Float32) Calculates 2 raised to the power of x.
exp2(Float64) Calculates 2 raised to the power of x.
floor(Float16) Rounds a floating-point number down to the nearest integer.
floor(Float32) Rounds a floating-point number down to the nearest integer.
floor(Float64) Rounds a floating-point number down to the nearest integer.
fmod(Float16, Float16) Calculates the remainder of dividing two half-precision floating-point numbers.
fmod(Float32, Float32) Calculates the remainder of dividing two single-precision floating-point numbers.
fmod(Float64, Float64) Calculates the remainder of dividing two double-precision floating-point numbers.
gamma(Float16) Calculates the Gamma function value of a floating-point number.
gamma(Float32) Calculates the Gamma function value of a floating-point number.
gamma(Float64) Calculates the Gamma function value of a floating-point number.
gcd(Int16, Int16) Calculates the greatest common divisor of two 16-bit signed integers.
[
rotate(UInt32, Int8) Computes the result of bitwise rotation for an integer.
rotate(UInt64, Int8) Computes the result of bitwise rotation for an integer.
rotate(UInt8, Int8) Computes the result of bitwise rotation for an integer.
round(Float16) This function computes the rounded value of a floating-point number using IEEE-754 round-to-nearest rules.
round(Float32) This function computes the rounded value of a floating-point number using IEEE-754 round-to-nearest rules.
round(Float64) This function computes the rounded value of a floating-point number using IEEE-754 round-to-nearest rules.
sin(Float16) Computes the sine function value for a half-precision floating-point number (input in radians).
sin(FFloat32) Computes the sine function value for a single-precision floating-point number (input in radians).
sin(Float64) Computes the sine function value for a double-precision floating-point number (input in radians).
sinh(Float16) Computes the hyperbolic sine function value for a half-precision floating-point number.
sinh(Float32) Computes the hyperbolic sine function value for a single-precision floating-point number.
sinh(Float64) Computes the hyperbolic sine function value for a double-precision floating-point number.
sqrt(Float16) Computes the arithmetic square root of a floating-point number.
sqrt(Float32) Computes the arithmetic square root of a floating-point number.
sqrt(Float64) Computes the arithmetic square root of a floating-point number.
tan(Float16) Computes the tangent function value for a half-precision floating-point number (input in radians).
tan(Float32) Computes the tangent function value for a single-precision floating-point number (input in radians).
tan(Float64) Computes the tangent function value for a double-precision floating-point number (input in radians).
tanh(Float16) Computes the hyperbolic tangent function value for a half-precision floating-point number.
tanh(Float32) Computes the hyperbolic tangent function value for a single-precision floating-point number.
tanh(Float64) Computes the hyperbolic tangent function value for a double-precision floating-point number.
trailingZeros(Int16) Counts the number of consecutive least significant bits set to 0 in the binary representation of a 16-bit signed integer. Returns 0 if the least significant bit is not 0.
trailingZeros(Int32) Counts the number of consecutive least significant bits set to 0 in the binary representation of a 32-bit signed integer. Returns 0 if the least significant bit is not 0.
trailingZeros(Int64) Counts the number of consecutive least significant bits set to 0 in the binary representation of a 64-bit signed integer. Returns 0 if the least significant bit is not 0.
trailingZeros(Int8) Counts the number of consecutive least significant bits set to 0 in the binary representation of an 8-bit signed integer. Returns 0 if the least significant bit is not 0.
trailingZeros(UInt16) Counts the number of consecutive least significant bits set to 0 in the binary representation of a 16-bit unsigned integer. Returns 0 if the least significant bit is not 0.
trailingZeros(UInt32) Counts the number of consecutive least significant bits set to 0 in the binary representation of a 32-bit unsigned integer. Returns 0 if the least significant bit is not 0.
trailingZeros(UInt64) Counts the number of consecutive least significant bits set to 0 in the binary representation of a 64-bit unsigned integer. Returns 0 if the least significant bit is not 0.
trailingZeros(UInt8) Counts the number of consecutive least significant bits set to 0 in the binary representation of an 8-bit unsigned integer. Returns 0 if the least significant bit is not 0.
trunc(Float16) Computes the truncated integer value of a floating-point number.
trunc(Float32) Computes the truncated integer value of a floating-point number.
trunc(Float64) Computes the truncated integer value of a floating-point number.

Interfaces

Interface Functionality
FloatingPoint<T> Provides methods related to floating-point numbers.
Integer<T> Provides methods related to integer types.
MathExtension (deprecated) Auxiliary interface for exporting properties (PI and E constants for floating-point numbers).
MaxMinValue<T> Provides methods to obtain maximum and minimum values.
Number<T> Provides methods related to numeric types.

Enums

Enum Functionality
RoundingMode Enumeration class for rounding modes, including 6 rounding rules. In addition to the 5 IEEE 754 standard rounding modes, it provides the commonly used "round half up" rule.