math #

Constants #

const (
	e        = 2.71828182845904523536028747135266249775724709369995957496696763
	pi       = 3.14159265358979323846264338327950288419716939937510582097494459
	phi      = 1.61803398874989484820458683436563811772030917980576286213544862
	tau      = 6.28318530717958647692528676655900576839433879875021164194988918
	sqrt2    = 1.41421356237309504880168872420969807856967187537694807317667974
	sqrt_e   = 1.64872127070012814684865078781416357165377610071014801157507931
	sqrt_pi  = 1.77245385090551602729816748334114518279754945612238712821380779
	sqrt_tau = 2.50662827463100050241576528481104525300698674060993831662992357
	sqrt_phi = 1.27201964951406896425242246173749149171560804184009624861664038
	ln2      = 0.693147180559945309417232121458176568075500134360255254120680009
	log2_e   = 1.0 / ln2
	ln10     = 2.30258509299404568401799145468436420760110148862877297603332790
	log10_e  = 1.0 / ln10
)
const (
	max_f32               = 3.40282346638528859811704183484516925440e+38
	smallest_non_zero_f32 = 1.401298464324817070923729583289916131280e-45
	max_f64               = 1.797693134862315708145274237317043567981e+308
	smallest_non_zero_f64 = 4.940656458412465441765687928682213723651e-324
)

Floating-point limit values max is the largest finite value representable by the type. smallest_non_zero is the smallest positive, non-zero value representable by the type.

const (
	max_i8  = 127
	min_i8  = -128
	max_i16 = 32767
	min_i16 = -32768
	max_i32 = 2147483647
	min_i32 = -2147483648
	min_i64 = i64(-9223372036854775807 - 1)
	max_i64 = i64(9223372036854775807)
	max_u8  = 255
	max_u16 = 65535
	max_u32 = u32(4294967295)
	max_u64 = u64(18446744073709551615)
)

Integer limit values

fn abs #

fn abs(a f64) f64

fn acos #

fn acos(a f64) f64

acos calculates inverse cosine (arccosine).

fn aprox_cos #

fn aprox_cos(a f64) f64

fn aprox_sin #

fn aprox_sin(a f64) f64

NOTE When adding a new function, please make sure it's in the right place. All functions are sorted alphabetically, separated by wrapped functions vs backend specific functions. If using System/Backend dependent functions, put them in their respective .c.v or .js.v or other files Below are functions that are not wrappers for built-in system functions, but native V functions. They are still sorted alphabetically Faster approximate sin() and cos() implemented from lolremez

fn asin #

fn asin(a f64) f64

asin calculates inverse sine (arcsine).

fn atan #

fn atan(a f64) f64

atan calculates inverse tangent (arctangent).

fn atan2 #

fn atan2(a f64, b f64) f64

atan2 calculates inverse tangent with two arguments, returns the angle between the X axis and the point.

fn cbrt #

fn cbrt(a f64) f64

cbrt calculates cubic root.

fn ceil #

fn ceil(a f64) f64

ceil returns the nearest f64 greater or equal to the provided value.

fn copysign #

fn copysign(x f64, y f64) f64

copysign returns a value with the magnitude of x and the sign of y

fn cos #

fn cos(a f64) f64

cos calculates cosine.

fn cosf #

fn cosf(a f32) f32

cosf calculates cosine. (float32)

fn cosh #

fn cosh(a f64) f64

cosh calculates hyperbolic cosine.

fn degrees #

fn degrees(radians f64) f64

degrees convert from degrees to radians.

fn digits #

fn digits(_n int, base int) []int

digits returns an array of the digits of n in the given base.

fn erf #

fn erf(a f64) f64

erf computes the error function value

fn erfc #

fn erfc(a f64) f64

erfc computes the complementary error function value

fn exp #

fn exp(a f64) f64

exp calculates exponent of the number (math.pow(math.E, a)).

fn exp2 #

fn exp2(a f64) f64

exp2 returns the base-2 exponential function of a (math.pow(2, a)).

fn f32_bits #

fn f32_bits(f f32) u32

f32_bits returns the IEEE 754 binary representation of f, with the sign bit of f and the result in the same bit position. f32_bits(f32_from_bits(x)) == x.

fn f32_from_bits #

fn f32_from_bits(b u32) f32

f32_from_bits returns the floating-point number corresponding to the IEEE 754 binary representation b, with the sign bit of b and the result in the same bit position. f32_from_bits(f32_bits(x)) == x.

fn f64_bits #

fn f64_bits(f f64) u64

f64_bits returns the IEEE 754 binary representation of f, with the sign bit of f and the result in the same bit position, and f64_bits(f64_from_bits(x)) == x.

fn f64_from_bits #

fn f64_from_bits(b u64) f64

f64_from_bits returns the floating-point number corresponding to the IEEE 754 binary representation b, with the sign bit of b and the result in the same bit position. f64_from_bits(f64_bits(x)) == x.

fn fabs #

fn fabs(x f64) f64

fn floor #

fn floor(a f64) f64

floor returns the nearest f64 lower or equal of the provided value.

fn fmod #

fn fmod(a f64, b f64) f64

fmod returns the floating-point remainder of number / denom (rounded towards zero):

fn gamma #

fn gamma(a f64) f64

gamma computes the gamma function value

fn gcd #

fn gcd(a_ i64, b_ i64) i64

gcd calculates greatest common (positive) divisor (or zero if a and b are both zero).

fn hypot #

fn hypot(a f64, b f64) f64

Returns hypotenuse of a right triangle.

fn inf #

fn inf(sign int) f64

inf returns positive infinity if sign >= 0, negative infinity if sign < 0.

fn is_inf #

fn is_inf(f f64, sign int) bool

is_inf reports whether f is an infinity, according to sign. If sign > 0, is_inf reports whether f is positive infinity. If sign < 0, is_inf reports whether f is negative infinity. If sign == 0, is_inf reports whether f is either infinity.

fn is_nan #

fn is_nan(f f64) bool

is_nan reports whether f is an IEEE 754 ``not-a-number'' value.

fn lcm #

fn lcm(a i64, b i64) i64

lcm calculates least common (non-negative) multiple.

fn log #

fn log(a f64) f64

log calculates natural (base-e) logarithm of the provided value.

fn log10 #

fn log10(a f64) f64

log10 calculates the common (base-10) logarithm of the provided value.

fn log2 #

fn log2(a f64) f64

log2 calculates base-2 logarithm of the provided value.

fn log_gamma #

fn log_gamma(a f64) f64

log_gamma computes the log-gamma function value

fn log_n #

fn log_n(a f64, b f64) f64

log_n calculates base-N logarithm of the provided value.

fn max #

fn max(a f64, b f64) f64

max returns the maximum value of the two provided.

fn min #

fn min(a f64, b f64) f64

min returns the minimum value of the two provided.

fn nan #

fn nan() f64

nan returns an IEEE 754 ``not-a-number'' value.

fn pow #

fn pow(a f64, b f64) f64

pow returns base raised to the provided power.

fn powf #

fn powf(a f32, b f32) f32

powf returns base raised to the provided power. (float32)

fn radians #

fn radians(degrees f64) f64

radians convert from radians to degrees.

fn round #

fn round(f f64) f64

round returns the integer nearest to the provided value.

fn sin #

fn sin(a f64) f64

sin calculates sine.

fn sinf #

fn sinf(a f32) f32

sinf calculates sine. (float32)

fn sinh #

fn sinh(a f64) f64

sinh calculates hyperbolic sine.

fn sqrt #

fn sqrt(a f64) f64

sqrt calculates square-root of the provided value.

fn sqrtf #

fn sqrtf(a f32) f32

sqrtf calculates square-root of the provided value. (float32)

fn tan #

fn tan(a f64) f64

tan calculates tangent.

fn tanf #

fn tanf(a f32) f32

tanf calculates tangent. (float32)

fn tanh #

fn tanh(a f64) f64

tanh calculates hyperbolic tangent.

fn trunc #

fn trunc(a f64) f64

trunc rounds a toward zero, returning the nearest integral value that is not larger in magnitude than a.