math.d.elv 9.2 KB

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