src.elv.sh@v0.21.0-dev.0.20240515223629-06979efb9a2a/pkg/mods/math/math.d.elv (about)

     1  #//each:eval use math
     2  #//only-on amd64 || arm64
     3  
     4  # Approximate value of
     5  # [`e`](https://en.wikipedia.org/wiki/E_(mathematical_constant)):
     6  # 2.718281.... This variable is read-only.
     7  var e
     8  
     9  # Approximate value of [`π`](https://en.wikipedia.org/wiki/Pi): 3.141592.... This
    10  # variable is read-only.
    11  var pi
    12  
    13  # Computes the absolute value `$number`. This function is exactness-preserving.
    14  # Examples:
    15  #
    16  # ```elvish-transcript
    17  # ~> math:abs 2
    18  # ▶ (num 2)
    19  # ~> math:abs -2
    20  # ▶ (num 2)
    21  # ~> math:abs 10000000000000000000
    22  # ▶ (num 10000000000000000000)
    23  # ~> math:abs -10000000000000000000
    24  # ▶ (num 10000000000000000000)
    25  # ~> math:abs 1/2
    26  # ▶ (num 1/2)
    27  # ~> math:abs -1/2
    28  # ▶ (num 1/2)
    29  # ~> math:abs 1.23
    30  # ▶ (num 1.23)
    31  # ~> math:abs -1.23
    32  # ▶ (num 1.23)
    33  # ```
    34  fn abs {|number| }
    35  
    36  # Outputs the arccosine of `$number`, in radians (not degrees). Examples:
    37  #
    38  # ```elvish-transcript
    39  # ~> math:acos 1
    40  # ▶ (num 0.0)
    41  # ~> math:acos 1.00001
    42  # ▶ (num NaN)
    43  # ```
    44  fn acos {|number| }
    45  
    46  # Outputs the inverse hyperbolic cosine of `$number`. Examples:
    47  #
    48  # ```elvish-transcript
    49  # ~> math:acosh 1
    50  # ▶ (num 0.0)
    51  # ~> math:acosh 0
    52  # ▶ (num NaN)
    53  # ```
    54  fn acosh {|number| }
    55  
    56  # Outputs the arcsine of `$number`, in radians (not degrees). Examples:
    57  #
    58  # ```elvish-transcript
    59  # ~> math:asin 0
    60  # ▶ (num 0.0)
    61  # ~> math:asin 1
    62  # ▶ (num 1.5707963267948966)
    63  # ~> math:asin 1.00001
    64  # ▶ (num NaN)
    65  # ```
    66  fn asin {|number| }
    67  
    68  # Outputs the inverse hyperbolic sine of `$number`. Examples:
    69  #
    70  # ```elvish-transcript
    71  # ~> math:asinh 0
    72  # ▶ (num 0.0)
    73  # ~> math:asinh inf
    74  # ▶ (num +Inf)
    75  # ```
    76  fn asinh {|number| }
    77  
    78  # Outputs the arctangent of `$number`, in radians (not degrees). Examples:
    79  #
    80  # ```elvish-transcript
    81  # ~> math:atan 0
    82  # ▶ (num 0.0)
    83  # ~> math:atan +inf
    84  # ▶ (num 1.5707963267948966)
    85  # ```
    86  fn atan {|number| }
    87  
    88  # Outputs the arc tangent of *y*/*x* in radians, using the signs of the two to
    89  # determine the quadrant of the return value. Examples:
    90  #
    91  # ```elvish-transcript
    92  # ~> math:atan2 0 0
    93  # ▶ (num 0.0)
    94  # ~> math:atan2 1 1
    95  # ▶ (num 0.7853981633974483)
    96  # ~> math:atan2 -1 -1
    97  # ▶ (num -2.356194490192345)
    98  # ```
    99  fn atan2 {|y x| }
   100  
   101  # Outputs the inverse hyperbolic tangent of `$number`. Examples:
   102  #
   103  # ```elvish-transcript
   104  # ~> math:atanh 0
   105  # ▶ (num 0.0)
   106  # ~> math:atanh 1
   107  # ▶ (num +Inf)
   108  # ```
   109  fn atanh {|number| }
   110  
   111  # Computes the least integer greater than or equal to `$number`. This function
   112  # is exactness-preserving.
   113  #
   114  # The results for the special floating-point values -0.0, +0.0, -Inf, +Inf and
   115  # NaN are themselves.
   116  #
   117  # Examples:
   118  #
   119  # ```elvish-transcript
   120  # ~> math:ceil 1
   121  # ▶ (num 1)
   122  # ~> math:ceil 3/2
   123  # ▶ (num 2)
   124  # ~> math:ceil -3/2
   125  # ▶ (num -1)
   126  # ~> math:ceil 1.1
   127  # ▶ (num 2.0)
   128  # ~> math:ceil -1.1
   129  # ▶ (num -1.0)
   130  # ```
   131  fn ceil {|number| }
   132  
   133  # Computes the cosine of `$number` in units of radians (not degrees).
   134  # Examples:
   135  #
   136  # ```elvish-transcript
   137  # ~> math:cos 0
   138  # ▶ (num 1.0)
   139  # ~> math:cos 3.14159265
   140  # ▶ (num -1.0)
   141  # ```
   142  fn cos {|number| }
   143  
   144  # Computes the hyperbolic cosine of `$number`. Example:
   145  #
   146  # ```elvish-transcript
   147  # ~> math:cosh 0
   148  # ▶ (num 1.0)
   149  # ```
   150  fn cosh {|number| }
   151  
   152  # Computes the greatest integer less than or equal to `$number`. This function
   153  # is exactness-preserving.
   154  #
   155  # The results for the special floating-point values -0.0, +0.0, -Inf, +Inf and
   156  # NaN are themselves.
   157  #
   158  # Examples:
   159  #
   160  # ```elvish-transcript
   161  # ~> math:floor 1
   162  # ▶ (num 1)
   163  # ~> math:floor 3/2
   164  # ▶ (num 1)
   165  # ~> math:floor -3/2
   166  # ▶ (num -2)
   167  # ~> math:floor 1.1
   168  # ▶ (num 1.0)
   169  # ~> math:floor -1.1
   170  # ▶ (num -2.0)
   171  # ```
   172  fn floor {|number| }
   173  
   174  # Tests whether the number is infinity. If sign > 0, tests whether `$number`
   175  # is positive infinity. If sign < 0, tests whether `$number` is negative
   176  # infinity. If sign == 0, tests whether `$number` is either infinity.
   177  #
   178  # ```elvish-transcript
   179  # ~> math:is-inf 123
   180  # ▶ $false
   181  # ~> math:is-inf inf
   182  # ▶ $true
   183  # ~> math:is-inf -inf
   184  # ▶ $true
   185  # ~> math:is-inf &sign=1 inf
   186  # ▶ $true
   187  # ~> math:is-inf &sign=-1 inf
   188  # ▶ $false
   189  # ~> math:is-inf &sign=-1 -inf
   190  # ▶ $true
   191  # ```
   192  fn is-inf {|&sign=0 number| }
   193  
   194  # Tests whether the number is a NaN (not-a-number).
   195  #
   196  # ```elvish-transcript
   197  # ~> math:is-nan 123
   198  # ▶ $false
   199  # ~> math:is-nan (num inf)
   200  # ▶ $false
   201  # ~> math:is-nan (num nan)
   202  # ▶ $true
   203  # ```
   204  fn is-nan {|number| }
   205  
   206  # Computes the natural (base *e*) logarithm of `$number`. Examples:
   207  #
   208  # ```elvish-transcript
   209  # ~> math:log 1.0
   210  # ▶ (num 0.0)
   211  # ~> math:log -2.3
   212  # ▶ (num NaN)
   213  # ```
   214  fn log {|number| }
   215  
   216  # Computes the base 10 logarithm of `$number`. Examples:
   217  #
   218  # ```elvish-transcript
   219  # ~> math:log10 100.0
   220  # ▶ (num 2.0)
   221  # ~> math:log10 -1.7
   222  # ▶ (num NaN)
   223  # ```
   224  fn log10 {|number| }
   225  
   226  # Computes the base 2 logarithm of `$number`. Examples:
   227  #
   228  # ```elvish-transcript
   229  # ~> math:log2 8
   230  # ▶ (num 3.0)
   231  # ~> math:log2 -5.3
   232  # ▶ (num NaN)
   233  # ```
   234  fn log2 {|number| }
   235  
   236  # Outputs the maximum number in the arguments. If there are no arguments,
   237  # an exception is thrown. If any number is NaN then NaN is output. This
   238  # function is exactness-preserving.
   239  #
   240  # Examples:
   241  #
   242  # ```elvish-transcript
   243  # ~> math:max 3 5 2
   244  # ▶ (num 5)
   245  # ~> math:max (range 100)
   246  # ▶ (num 99)
   247  # ~> math:max 1/2 1/3 2/3
   248  # ▶ (num 2/3)
   249  # ```
   250  fn max {|@number| }
   251  
   252  # Outputs the minimum number in the arguments. If there are no arguments
   253  # an exception is thrown. If any number is NaN then NaN is output. This
   254  # function is exactness-preserving.
   255  #
   256  # Examples:
   257  #
   258  # ```elvish-transcript
   259  # ~> math:min
   260  # Exception: arity mismatch: arguments must be 1 or more values, but is 0 values
   261  #   [tty]:1:1-8: math:min
   262  # ~> math:min 3 5 2
   263  # ▶ (num 2)
   264  # ~> math:min 1/2 1/3 2/3
   265  # ▶ (num 1/3)
   266  # ```
   267  fn min {|@number| }
   268  
   269  # Outputs the result of raising `$base` to the power of `$exponent`.
   270  #
   271  # This function produces an exact result when `$base` is exact and `$exponent`
   272  # is an exact integer. Otherwise it produces an inexact result.
   273  #
   274  # Examples:
   275  #
   276  # ```elvish-transcript
   277  # ~> math:pow 3 2
   278  # ▶ (num 9)
   279  # ~> math:pow -2 2
   280  # ▶ (num 4)
   281  # ~> math:pow 1/2 3
   282  # ▶ (num 1/8)
   283  # ~> math:pow 1/2 -3
   284  # ▶ (num 8)
   285  # ~> math:pow 9 1/2
   286  # ▶ (num 3.0)
   287  # ~> math:pow 12 1.1
   288  # ▶ (num 15.38506624784179)
   289  # ```
   290  fn pow {|base exponent| }
   291  
   292  # Outputs the nearest integer, rounding half away from zero. This function is
   293  # exactness-preserving.
   294  #
   295  # The results for the special floating-point values -0.0, +0.0, -Inf, +Inf and
   296  # NaN are themselves.
   297  #
   298  # Examples:
   299  #
   300  # ```elvish-transcript
   301  # ~> math:round 2
   302  # ▶ (num 2)
   303  # ~> math:round 1/3
   304  # ▶ (num 0)
   305  # ~> math:round 1/2
   306  # ▶ (num 1)
   307  # ~> math:round 2/3
   308  # ▶ (num 1)
   309  # ~> math:round -1/3
   310  # ▶ (num 0)
   311  # ~> math:round -1/2
   312  # ▶ (num -1)
   313  # ~> math:round -2/3
   314  # ▶ (num -1)
   315  # ~> math:round 2.5
   316  # ▶ (num 3.0)
   317  # ```
   318  fn round {|number| }
   319  
   320  # Outputs the nearest integer, rounding ties to even. This function is
   321  # exactness-preserving.
   322  #
   323  # The results for the special floating-point values -0.0, +0.0, -Inf, +Inf and
   324  # NaN are themselves.
   325  #
   326  # Examples:
   327  #
   328  # ```elvish-transcript
   329  # ~> math:round-to-even 2
   330  # ▶ (num 2)
   331  # ~> math:round-to-even 1/2
   332  # ▶ (num 0)
   333  # ~> math:round-to-even 3/2
   334  # ▶ (num 2)
   335  # ~> math:round-to-even 5/2
   336  # ▶ (num 2)
   337  # ~> math:round-to-even -5/2
   338  # ▶ (num -2)
   339  # ~> math:round-to-even 2.5
   340  # ▶ (num 2.0)
   341  # ~> math:round-to-even 1.5
   342  # ▶ (num 2.0)
   343  # ```
   344  fn round-to-even {|number| }
   345  
   346  # Computes the sine of `$number` in units of radians (not degrees). Examples:
   347  #
   348  # ```elvish-transcript
   349  # ~> math:sin 0
   350  # ▶ (num 0.0)
   351  # ~> math:sin 3.14159265
   352  # ▶ (num 3.5897930298416118e-09)
   353  # ```
   354  fn sin {|number| }
   355  
   356  # Computes the hyperbolic sine of `$number`. Example:
   357  #
   358  # ```elvish-transcript
   359  # ~> math:sinh 0
   360  # ▶ (num 0.0)
   361  # ```
   362  fn sinh {|number| }
   363  
   364  # Computes the square-root of `$number`. Examples:
   365  #
   366  # ```elvish-transcript
   367  # ~> math:sqrt 0
   368  # ▶ (num 0.0)
   369  # ~> math:sqrt 4
   370  # ▶ (num 2.0)
   371  # ~> math:sqrt -4
   372  # ▶ (num NaN)
   373  # ```
   374  fn sqrt {|number| }
   375  
   376  # Computes the tangent of `$number` in units of radians (not degrees). Examples:
   377  #
   378  # ```elvish-transcript
   379  # ~> math:tan 0
   380  # ▶ (num 0.0)
   381  # ~> math:tan 3.14159265
   382  # ▶ (num -0.0000000035897930298416118)
   383  # ```
   384  fn tan {|number| }
   385  
   386  # Computes the hyperbolic tangent of `$number`. Example:
   387  #
   388  # ```elvish-transcript
   389  # ~> math:tanh 0
   390  # ▶ (num 0.0)
   391  # ```
   392  fn tanh {|number| }
   393  
   394  # Outputs the integer portion of `$number`. This function is exactness-preserving.
   395  #
   396  # The results for the special floating-point values -0.0, +0.0, -Inf, +Inf and
   397  # NaN are themselves.
   398  #
   399  # Examples:
   400  #
   401  # ```elvish-transcript
   402  # ~> math:trunc 1
   403  # ▶ (num 1)
   404  # ~> math:trunc 3/2
   405  # ▶ (num 1)
   406  # ~> math:trunc 5/3
   407  # ▶ (num 1)
   408  # ~> math:trunc -3/2
   409  # ▶ (num -1)
   410  # ~> math:trunc -5/3
   411  # ▶ (num -1)
   412  # ~> math:trunc 1.7
   413  # ▶ (num 1.0)
   414  # ~> math:trunc -1.7
   415  # ▶ (num -1.0)
   416  # ```
   417  fn trunc {|number| }