elvish-math(7)
💅 elvish-math(7) — the math module but make it a whole personality 💅
okay bestie, come sit with me. this is a page from the Miscellaneous Information Manual, and it's literally just the glow-up guide for Elvish's math: module. 🧚✨
🌸 Introduction 🌸
The math: module provides mathematical functions and constants.
Function usages are given in the same format as in the reference doc for the builtin module. In particular, all the commands in this module conform to the convention of numeric commands. no cap, they all play by the same rules 💖
🎀 Variables 🎀
$math:e {#math:e}
$math:e
Approximate value of e (https://en.wikipedia.org/wiki/E_(mathematical_constant)): 2.718281.... This variable is read-only. like, don't even try to change it, she said no 🙅♀️
$math:pi {#math:pi}
$math:pi
Approximate value of π (https://en.wikipedia.org/wiki/Pi): 3.141592.... This variable is read-only. also unchangeable, also iconic 🥧
✨ Functions ✨
math:abs {#math:abs}
math:abs $number
Computes the absolute value $number. This function is exactness-preserving. Examples:
~> math:abs 2
▶ (num 2)
~> math:abs -2
▶ (num 2)
~> math:abs 10000000000000000000
▶ (num 10000000000000000000)
~> math:abs -10000000000000000000
▶ (num 10000000000000000000)
~> math:abs 1/2
▶ (num 1/2)
~> math:abs -1/2
▶ (num 1/2)
~> math:abs 1.23
▶ (num 1.23)
~> math:abs -1.23
▶ (num 1.23)
negativity? never heard of her 💅
math:acos {#math:acos}
math:acos $number
Outputs the arccosine of $number, in radians (not degrees, bestie, we're not doing degrees here). Examples:
~> math:acos 1
▶ (float64 1)
~> math:acos 1.00001
▶ (float64 NaN)
math:acosh {#math:acosh}
math:acosh $number
Outputs the inverse hyperbolic cosine of $number. Examples:
~> math:acosh 1
▶ (float64 0)
~> math:acosh 0
▶ (float64 NaN)
math:asin {#math:asin}
math:asin $number
Outputs the arcsine of $number, in radians (again: radians, not degrees). Examples:
~> math:asin 0
▶ (float64 0)
~> math:asin 1
▶ (float64 1.5707963267948966)
~> math:asin 1.00001
▶ (float64 NaN)
math:asinh {#math:asinh}
math:asinh $number
Outputs the inverse hyperbolic sine of $number. Examples:
~> math:asinh 0
▶ (float64 0)
~> math:asinh inf
▶ (float64 +Inf)
math:atan {#math:atan}
math:atan $number
Outputs the arctangent of $number, in radians (you already know). Examples:
~> math:atan 0
▶ (float64 0)
~> math:atan $math:inf
▶ (float64 1.5707963267948966)
math:atanh {#math:atanh}
math:atanh $number
Outputs the inverse hyperbolic tangent of $number. Examples:
~> math:atanh 0
▶ (float64 0)
~> math:atanh 1
▶ (float64 +Inf)
math:ceil {#math:ceil}
math:ceil $number
Computes the least integer greater than or equal to $number. This function is exactness-preserving.
The results for the special floating-point values -0.0, +0.0, -Inf, +Inf and NaN are themselves. (they show up as themselves, they're doing self-care 🫶)
Examples:
~> math:floor 1
▶ (num 1)
~> math:floor 3/2
▶ (num 1)
~> math:floor -3/2
▶ (num -2)
~> math:floor 1.1
▶ (num 1.0)
~> math:floor -1.1
▶ (num -2.0)
💀 real talk: the examples above are literally the ones printed under this entry in the page. I'm not fixing them, I'm not touching them, I'm just delivering them to you exactly as they arrived. periodt.
math:cos {#math:cos}
math:cos $number
Computes the cosine of $number in units of radians (not degrees). Examples:
~> math:cos 0
▶ (float64 1)
~> math:cos 3.14159265
▶ (float64 -1)
math:cosh {#math:cosh}
math:cosh $number
Computes the hyperbolic cosine of $number. Example:
~> math:cosh 0
▶ (float64 1)
math:floor {#math:floor}
math:floor $number
Computes the greatest integer less than or equal to $number. This function is exactness-preserving.
The results for the special floating-point values -0.0, +0.0, -Inf, +Inf and NaN are themselves.
Examples:
~> math:floor 1
▶ (num 1)
~> math:floor 3/2
▶ (num 1)
~> math:floor -3/2
▶ (num -2)
~> math:floor 1.1
▶ (num 1.0)
~> math:floor -1.1
▶ (num -2.0)
math:is-inf {#math:is-inf}
math:is-inf &sign=0 $number
Tests whether the number is infinity. If sign > 0, tests whether $number is positive infinity. If sign < 0, tests whether $number is negative infinity. If sign == 0, tests whether $number is either infinity. it's giving vibe check for infinity 🌈
~> math:is-inf 123
▶ $false
~> math:is-inf inf
▶ $true
~> math:is-inf -inf
▶ $true
~> math:is-inf &sign=1 inf
▶ $true
~> math:is-inf &sign=-1 inf
▶ $false
~> math:is-inf &sign=-1 -inf
▶ $true
math:is-nan {#math:is-nan}
math:is-nan $number
Tests whether the number is a NaN (not-a-number).
~> math:is-nan 123
▶ $false
~> math:is-nan (float64 inf)
▶ $false
~> math:is-nan (float64 nan)
▶ $true
math:log {#math:log}
math:log $number
Computes the natural (base e) logarithm of $number. Examples:
~> math:log 1.0
▶ (float64 1)
~> math:log -2.3
▶ (float64 NaN)
math:log10 {#math:log10}
math:log10 $number
Computes the base 10 logarithm of $number. Examples:
~> math:log10 100.0
▶ (float64 2)
~> math:log10 -1.7
▶ (float64 NaN)
math:log2 {#math:log2}
math:log2 $number
Computes the base 2 logarithm of $number. Examples:
~> math:log2 8
▶ (float64 3)
~> math:log2 -5.3
▶ (float64 NaN)
math:max {#math:max}
math:max $number...
Outputs the maximum number in the arguments. If there are no arguments, an exception is thrown. If any number is NaN then NaN is output. This function is exactness-preserving.
Examples:
~> math:max 3 5 2
▶ (num 5)
~> math:max (range 100)
▶ (num 99)
~> math:max 1/2 1/3 2/3
▶ (num 2/3)
math:min {#math:min}
math:min $number...
Outputs the minimum number in the arguments. If there are no arguments an exception is thrown. If any number is NaN then NaN is output. This function is exactness-preserving.
Examples:
~> math:min
Exception: arity mismatch: arguments must be 1 or more values, but is 0 values
[tty 17], line 1: math:min
~> math:min 3 5 2
▶ (num 2)
~> math:min 1/2 1/3 2/3
▶ (num 1/3)
🫶 she said "at least one argument or we're not doing this" and honestly? valid.
math:pow {#math:pow}
math:pow $base $exponent
Outputs the result of raising $base to the power of $exponent.
This function produces an exact result when $base is exact and $exponent is an exact integer. Otherwise it produces an inexact result.
Examples:
~> math:pow 3 2
▶ (num 9)
~> math:pow -2 2
▶ (num 4)
~> math:pow 1/2 3
▶ (num 1/8)
~> math:pow 1/2 -3
▶ (num 8)
~> math:pow 9 1/2
▶ (num 3.0)
~> math:pow 12 1.1
▶ (num 15.38506624784179)
math:round {#math:round}
math:round $number
Outputs the nearest integer, rounding half away from zero. This function is exactness-preserving.
The results for the special floating-point values -0.0, +0.0, -Inf, +Inf and NaN are themselves.
Examples:
~> math:round 2
▶ (num 2)
~> math:round 1/3
▶ (num 0)
~> math:round 1/2
▶ (num 1)
~> math:round 2/3
▶ (num 1)
~> math:round -1/3
▶ (num 0)
~> math:round -1/2
▶ (num -1)
~> math:round -2/3
▶ (num -1)
~> math:round 2.5
▶ (num 3.0)
math:round-to-even {#math:round-to-even}
math:round-to-even $number
Outputs the nearest integer, rounding ties to even. This function is exactness-preserving.
The results for the special floating-point values -0.0, +0.0, -Inf, +Inf and NaN are themselves.
Examples:
~> math:round-to-even 2
▶ (num 2)
~> math:round-to-even 1/2
▶ (num 0)
~> math:round-to-even 3/2
▶ (num 2)
~> math:round-to-even 5/2
▶ (num 2)
~> math:round-to-even -5/2
▶ (num -2)
~> math:round-to-even 2.5
▶ (num 2.0)
~> math:round-to-even 1.5
▶ (num 2.0)
the even numbers are getting picked and the odds are lowkey in their feels, but that's just the rules 🎀
math:sin {#math:sin}
math:sin $number
Computes the sine of $number in units of radians (not degrees). Examples:
~> math:sin 0
▶ (float64 0)
~> math:sin 3.14159265
▶ (float64 3.5897930298416118e-09)
math:sinh {#math:sinh}
math:sinh $number
Computes the hyperbolic sine of $number. Example:
~> math:sinh 0
▶ (float64 0)
math:sqrt {#math:sqrt}
math:sqrt $number
Computes the square-root of $number. Examples:
~> math:sqrt 0
▶ (float64 0)
~> math:sqrt 4
▶ (float64 2)
~> math:sqrt -4
▶ (float64 NaN)
math:tan {#math:tan}
math:tan $number
Computes the tangent of $number in units of radians (not degrees). Examples:
~> math:tan 0
▶ (float64 0)
~> math:tan 3.14159265
▶ (float64 -0.0000000035897930298416118)
math:tanh {#math:tanh}
math:tanh $number
Computes the hyperbolic tangent of $number. Example:
~> math:tanh 0
▶ (float64 0)
math:trunc {#math:trunc}
math:trunc $number
Outputs the integer portion of $number. This function is exactness-preserving.
The results for the special floating-point values -0.0, +0.0, -Inf, +Inf and NaN are themselves.
Examples:
~> math:trunc 1
▶ (num 1)
~> math:trunc 3/2
▶ (num 1)
~> math:trunc 5/3
▶ (num 1)
~> math:trunc -3/2
▶ (num -1)
~> math:trunc -5/3
▶ (num -1)
~> math:trunc 1.7
▶ (num 1.0)
~> math:trunc -1.7
▶ (num -1.0)
and that's the whole module, bestie. go forth and compute. 🦋
💖 this page came to you from Elvish 0.17.0, dated Nov 18, 2024 💖
📦 where this page comes from
- ubuntu jammy: elvish 0.17.0-1ubuntu0.1 · BSD-2-Clause
- 💖 girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms