The std.math module provides mathematical constants and functions for numerical operations.
PI: The mathematical constant π (pi), approximately 3.14159E: The mathematical constant e (Euler's number), approximately 2.71828TAU: The mathematical constant τ (tau), equal to 2πINFINITY: Represents positive infinityNEG_INFINITY: Represents negative infinityNAN: Represents "Not a Number"Adds two numbers.
Parameters:
a: First number to addb: Second number to addReturn Type: number
Example:
Subtracts the second number from the first.
Parameters:
a: Number to subtract fromb: Number to subtractReturn Type: number
Example:
Multiplies two numbers.
Parameters:
a: First number to multiplyb: Second number to multiplyReturn Type: number
Example:
Divides the first number by the second.
Parameters:
a: Number to divideb: Number to divide byReturn Type: number
Example:
Performs integer division, rounding down to the nearest integer.
Parameters:
a: Number to divideb: Number to divide byReturn Type: number
Example:
Calculates the square root of a number.
Parameters:
x: Number to calculate square root ofReturn Type: number
Example:
Raises a number to the specified power.
Parameters:
base: The base numberexponent: The power to raise the base toReturn Type: number
Example:
Calculates the natural logarithm (base e) of a number.
Parameters:
x: Number to calculate logarithm ofReturn Type: number
Example:
Calculates the sine of an angle (in radians).
Parameters:
x: Angle in radiansReturn Type: number
Example:
Calculates the cosine of an angle (in radians).
Parameters:
x: Angle in radiansReturn Type: number
Example:
Calculates the tangent of an angle (in radians).
Parameters:
x: Angle in radiansReturn Type: number
Example:
Calculates the arcsine (inverse sine) of a number.
Parameters:
x: Number between -1 and 1Return Type: number
Example:
Calculates the arccosine (inverse cosine) of a number.
Parameters:
x: Number between -1 and 1Return Type: number
Example:
Rounds a number down to the nearest integer.
Parameters:
x: Number to round downReturn Type: number
Example:
Rounds a number up to the nearest integer.
Parameters:
x: Number to round upReturn Type: number
Example:
Rounds a number to the nearest integer.
Parameters:
x: Number to roundReturn Type: number
Example:
Returns the absolute value of a number.
Parameters:
x: Number to get absolute value ofReturn Type: number
Example:
Returns the smaller of two numbers.
Parameters:
a: First number to compareb: Second number to compareReturn Type: number
Example:
Returns the larger of two numbers.
Parameters:
a: First number to compareb: Second number to compareReturn Type: number
Example: