code / tomo

Lines41.3K C23.7K Markdown9.7K YAML5.0K Tomo2.3K
7 others 763
Python231 Shell230 make212 INI47 Text21 SVG16 Lua6
(969 lines)
1 Num.abs:
2 short: absolute value
3 description: >
4 Calculates the absolute value of a number.
5 return:
6 type: 'Num'
7 description: >
8 The absolute value of `n`.
9 args:
10 n:
11 type: 'Num'
12 description: >
13 The number whose absolute value is to be computed.
14 example: |
15 assert (-3.5).abs() == 3.5
17 Num.acos:
18 short: arc cosine
19 description: >
20 Computes the arc cosine of a number.
21 return:
22 type: 'Num'
23 description: >
24 The arc cosine of `x` in radians.
25 args:
26 x:
27 type: 'Num'
28 description: >
29 The number for which the arc cosine is to be calculated.
30 example: |
31 assert (0.0).acos().near(1.5707963267948966)
33 Num.acosh:
34 short: arc hyperbolic cosine
35 description: >
36 Computes the inverse hyperbolic cosine of a number.
37 return:
38 type: 'Num'
39 description: >
40 The inverse hyperbolic cosine of `x`.
41 args:
42 x:
43 type: 'Num'
44 description: >
45 The number for which the inverse hyperbolic cosine is to be calculated.
46 example: |
47 assert (1.0).acosh() == 0
49 Num.asin:
50 short: arc sine
51 description: >
52 Computes the arc sine of a number.
53 return:
54 type: 'Num'
55 description: >
56 The arc sine of `x` in radians.
57 args:
58 x:
59 type: 'Num'
60 description: >
61 The number for which the arc sine is to be calculated.
62 example: |
63 assert (0.5).asin().near(0.5235987755982989)
65 Num.asinh:
66 short: arc hyperbolic sine
67 description: >
68 Computes the inverse hyperbolic sine of a number.
69 return:
70 type: 'Num'
71 description: >
72 The inverse hyperbolic sine of `x`.
73 args:
74 x:
75 type: 'Num'
76 description: >
77 The number for which the inverse hyperbolic sine is to be calculated.
78 example: |
79 assert (0.0).asinh() == 0
81 Num.atan:
82 short: arc tangent
83 description: >
84 Computes the arc tangent of a number.
85 return:
86 type: 'Num'
87 description: >
88 The arc tangent of `x` in radians.
89 args:
90 x:
91 type: 'Num'
92 description: >
93 The number for which the arc tangent is to be calculated.
94 example: |
95 assert (1.0).atan().near(0.7853981633974483)
97 Num.atan2:
98 short: arc tangent from 2 variables
99 description: >
100 Computes the arc tangent of the quotient of two numbers.
101 return:
102 type: 'Num'
103 description: >
104 The arc tangent of `x/y` in radians.
105 args:
107 type: 'Num'
108 description: >
109 The numerator.
111 type: 'Num'
112 description: >
113 The denominator.
114 example: |
115 assert Num.atan2(1, 1).near(0.7853981633974483)
117 Num.atanh:
118 short: arc hyperbolic tangent.
119 description: >
120 Computes the inverse hyperbolic tangent of a number.
121 return:
122 type: 'Num'
123 description: >
124 The inverse hyperbolic tangent of `x`.
125 args:
127 type: 'Num'
128 description: >
129 The number for which the inverse hyperbolic tangent is to be calculated.
130 example: |
131 assert (0.5).atanh().near(0.5493061443340549)
133 Num.cbrt:
134 short: cube root
135 description: >
136 Computes the cube root of a number.
137 return:
138 type: 'Num'
139 description: >
140 The cube root of `x`.
141 args:
143 type: 'Num'
144 description: >
145 The number for which the cube root is to be calculated.
146 example: |
147 assert (27.0).cbrt() == 3
149 Num.ceil:
150 short: ceiling function
151 description: >
152 Rounds a number up to the nearest integer.
153 return:
154 type: 'Num'
155 description: >
156 The smallest integer greater than or equal to `x`.
157 args:
159 type: 'Num'
160 description: >
161 The number to be rounded up.
162 example: |
163 assert (3.2).ceil() == 4
165 Num.clamped:
166 short: clamp a number
167 description: >
168 Returns the given number clamped between two values so that it is within
169 that range.
170 return:
171 type: 'Num'
172 description: >
173 The first argument clamped between the other two arguments.
174 args:
176 type: 'Num'
177 description: >
178 The number to clamp.
179 low:
180 type: 'Num'
181 description: >
182 The lowest value the result can take.
183 high:
184 type: 'Num'
185 description: >
186 The highest value the result can take.
187 example: |
188 assert (2.5).clamped(5.5, 10.5) == 5.5
190 Num.copysign:
191 short: copy a number's sign
192 description: >
193 Copies the sign of one number to another.
194 return:
195 type: 'Num'
196 description: >
197 A number with the magnitude of `x` and the sign of `y`.
198 args:
200 type: 'Num'
201 description: >
202 The number whose magnitude will be copied.
204 type: 'Num'
205 description: >
206 The number whose sign will be copied.
207 example: |
208 assert (3.0).copysign(-1) == -3
210 Num.cos:
211 short: cosine
212 description: >
213 Computes the cosine of a number (angle in radians).
214 return:
215 type: 'Num'
216 description: >
217 The cosine of `x`.
218 args:
220 type: 'Num'
221 description: >
222 The angle in radians.
223 example: |
224 assert (0.0).cos() == 1
226 Num.cosh:
227 short: hyperbolic cosine
228 description: >
229 Computes the hyperbolic cosine of a number.
230 return:
231 type: 'Num'
232 description: >
233 The hyperbolic cosine of `x`.
234 args:
236 type: 'Num'
237 description: >
238 The number for which the hyperbolic cosine is to be calculated.
239 example: |
240 assert (0.0).cosh() == 1
242 Num.erf:
243 short: error function
244 description: >
245 Computes the error function of a number.
246 return:
247 type: 'Num'
248 description: >
249 The error function of `x`.
250 args:
252 type: 'Num'
253 description: >
254 The number for which the error function is to be calculated.
255 example: |
256 assert (0.0).erf() == 0
258 Num.erfc:
259 short: complimentary error function
260 description: >
261 Computes the complementary error function of a number.
262 return:
263 type: 'Num'
264 description: >
265 The complementary error function of `x`.
266 args:
268 type: 'Num'
269 description: >
270 The number for which the complementary error function is to be calculated.
271 example: |
272 assert (0.0).erfc() == 1
274 Num.exp:
275 short: base-e exponentiation
276 description: >
277 Computes the exponential function $e^x$ for a number.
278 return:
279 type: 'Num'
280 description: >
281 The value of $e^x$.
282 args:
284 type: 'Num'
285 description: >
286 The exponent.
287 example: |
288 assert (1.0).exp().near(2.718281828459045)
290 Num.exp2:
291 short: base-2 exponentiation
292 description: >
293 Computes $2^x$ for a number.
294 return:
295 type: 'Num'
296 description: >
297 The value of $2^x$.
298 args:
300 type: 'Num'
301 description: >
302 The exponent.
303 example: |
304 assert (3.0).exp2() == 8
306 Num.expm1:
307 short: base-e exponential minus 1
308 description: >
309 Computes $e^x - 1$ for a number.
310 return:
311 type: 'Num'
312 description: >
313 The value of $e^x - 1$.
314 args:
316 type: 'Num'
317 description: >
318 The exponent.
319 example: |
320 assert (1.0).expm1().near(1.7182818284590453)
322 Num.fdim:
323 short: positive difference
324 description: >
325 Computes the positive difference between two numbers.
326 return:
327 type: 'Num'
328 description: >
329 The positive difference $\max(0, x - y)$.
330 args:
332 type: 'Num'
333 description: >
334 The first number.
336 type: 'Num'
337 description: >
338 The second number.
339 example: |
340 assert (5.0).fdim(3) == 2
342 Num.floor:
343 short: floor function
344 description: >
345 Rounds a number down to the nearest integer.
346 return:
347 type: 'Num'
348 description: >
349 The largest integer less than or equal to `x`.
350 args:
352 type: 'Num'
353 description: >
354 The number to be rounded down.
355 example: |
356 assert (3.7).floor() == 3
358 Num.hypot:
359 short: Euclidean distance function
360 description: >
361 Computes the Euclidean norm, $\sqrt{x^2 + y^2}$, of two numbers.
362 return:
363 type: 'Num'
364 description: >
365 The Euclidean norm of `x` and `y`.
366 args:
368 type: 'Num'
369 description: >
370 The first number.
372 type: 'Num'
373 description: >
374 The second number.
375 example: |
376 assert Num.hypot(3, 4) == 5
378 Num.isfinite:
379 short: check for finite number
380 description: >
381 Checks if a number is finite.
382 return:
383 type: 'Bool'
384 description: >
385 `yes` if `n` is finite, `no` otherwise.
386 args:
388 type: 'Num'
389 description: >
390 The number to be checked.
391 example: |
392 assert (1.0).isfinite() == yes
393 assert Num.INF.isfinite() == no
395 Num.is_between:
396 short: check if a number is in a range
397 description: >
398 Determines if a number is between two numbers (inclusive).
399 return:
400 type: 'Bool'
401 description: >
402 `yes` if `a <= x and x <= b` or `b <= x and x <= a`, otherwise `no`
403 args:
405 type: 'Num'
406 description: >
407 The integer to be checked.
408 low:
409 type: 'Num'
410 description: >
411 One end of the range to check (inclusive).
412 high:
413 type: 'Num'
414 description: >
415 The other end of the range to check (inclusive).
416 example: |
417 assert (7.5).is_between(1, 10) == yes
418 assert (7.5).is_between(10, 1) == yes
419 assert (7.5).is_between(100, 200) == no
420 assert (7.5).is_between(1, 7.5) == yes
422 Num.isinf:
423 short: check for infinite number
424 description: >
425 Checks if a number is infinite.
426 return:
427 type: 'Bool'
428 description: >
429 `yes` if `n` is infinite, `no` otherwise.
430 args:
432 type: 'Num'
433 description: >
434 The number to be checked.
435 example: |
436 assert Num.INF.isinf() == yes
437 assert (1.0).isinf() == no
439 Num.j0:
440 short: Bessel function
441 description: >
442 Computes the Bessel function of the first kind of order 0.
443 return:
444 type: 'Num'
445 description: >
446 The Bessel function of the first kind of order 0 of `x`.
447 args:
449 type: 'Num'
450 description: >
451 The number for which the Bessel function is to be calculated.
452 example: |
453 assert (0.0).j0() == 1
455 Num.j1:
456 short: Bessel function
457 description: >
458 Computes the Bessel function of the first kind of order 1.
459 return:
460 type: 'Num'
461 description: >
462 The Bessel function of the first kind of order 1 of `x`.
463 args:
465 type: 'Num'
466 description: >
467 The number for which the Bessel function is to be calculated.
468 example: |
469 assert (0.0).j1() == 0
471 Num.log:
472 short: natural logarithm
473 description: >
474 Computes the natural logarithm (base $e$) of a number.
475 return:
476 type: 'Num'
477 description: >
478 The natural logarithm of `x`.
479 args:
481 type: 'Num'
482 description: >
483 The number for which the natural logarithm is to be calculated.
484 example: |
485 assert Num.E.log() == 1
487 Num.log10:
488 short: logarithm base-10
489 description: >
490 Computes the base-10 logarithm of a number.
491 return:
492 type: 'Num'
493 description: >
494 The base-10 logarithm of `x`.
495 args:
497 type: 'Num'
498 description: >
499 The number for which the base-10 logarithm is to be calculated.
500 example: |
501 assert (100.0).log10() == 2
503 Num.log1p:
504 short: logarithm of 1 plus x
505 description: >
506 Computes $\log(1 + x)$ for a number.
507 return:
508 type: 'Num'
509 description: >
510 The value of $\log(1 + x)$.
511 args:
513 type: 'Num'
514 description: >
515 The number for which $\log(1 + x)$ is to be calculated.
516 example: |
517 assert (1.0).log1p().near(0.6931471805599453)
519 Num.log2:
520 short: logarithm base-2
521 description: >
522 Computes the base-2 logarithm of a number.
523 return:
524 type: 'Num'
525 description: >
526 The base-2 logarithm of `x`.
527 args:
529 type: 'Num'
530 description: >
531 The number for which the base-2 logarithm is to be calculated.
532 example: |
533 assert (8.0).log2() == 3
535 Num.logb:
536 short: exponent of a floating point value
537 description: >
538 Computes the binary exponent (base-2 logarithm) of a number.
539 return:
540 type: 'Num'
541 description: >
542 The binary exponent of `x`.
543 args:
545 type: 'Num'
546 description: >
547 The number for which the binary exponent is to be calculated.
548 example: |
549 assert (8.0).logb() == 3
551 Num.mix:
552 short: mix two numbers by an amount
553 description: >
554 Interpolates between two numbers based on a given amount.
555 return:
556 type: 'Num'
557 description: >
558 The interpolated number between `x` and `y` based on `amount`.
559 args:
560 amount:
561 type: 'Num'
562 description: >
563 The interpolation factor (between `0` and `1`).
565 type: 'Num'
566 description: >
567 The starting number.
569 type: 'Num'
570 description: >
571 The ending number.
572 example: |
573 assert (0.5).mix(10, 20) == 15
574 assert (0.25).mix(10, 20) == 12.5
576 Num.near:
577 short: check if two numbers are near each other
578 description: >
579 Checks if two numbers are approximately equal within specified tolerances. If
580 two numbers are within an absolute difference or the ratio between the two is
581 small enough, they are considered near each other.
582 return:
583 type: 'Bool'
584 description: >
585 `yes` if `x` and `y` are approximately equal within the specified tolerances, `no` otherwise.
586 args:
588 type: 'Num'
589 description: >
590 The first number.
592 type: 'Num'
593 description: >
594 The second number.
595 ratio:
596 type: 'Num'
597 default: '1e-9'
598 description: >
599 The relative tolerance. Default is `1e-9`.
600 min_epsilon:
601 type: 'Num'
602 default: '1e-9'
603 description: >
604 The absolute tolerance. Default is `1e-9`.
605 example: |
606 assert (1.0).near(1.000000001) == yes
607 assert (100.0).near(110, ratio=0.1) == yes
608 assert (5.0).near(5.1, min_epsilon=0.1) == yes
610 Num.nextafter:
611 short: next floating point number
612 description: >
613 Computes the next representable value after a given number towards a specified direction.
614 return:
615 type: 'Num'
616 description: >
617 The next representable value after `x` in the direction of `y`.
618 args:
620 type: 'Num'
621 description: >
622 The starting number.
624 type: 'Num'
625 description: >
626 The direction towards which to find the next representable value.
627 example: |
628 assert (1.0).nextafter(1.1) == 1.0000000000000002
630 Num.parse:
631 short: convert text to number
632 description: >
633 Converts a text representation of a number into a floating-point number.
634 return:
635 type: 'Num?'
636 description: >
637 The number represented by the text or `none` if the entire text can't be parsed
638 as a number.
639 args:
640 text:
641 type: 'Text'
642 description: >
643 The text containing the number.
644 remainder:
645 type: '&Text?'
646 default: 'none'
647 description: >
648 If non-none, this argument will be set to the remainder of the text after the matching part.
649 If none, parsing will only succeed if the entire text matches.
650 example: |
651 assert Num.parse("3.14") == 3.14
652 assert Num.parse("1e3") == 1000
653 assert Num.parse("1.5junk") == none
654 remainder : Text
655 assert Num.parse("1.5junk", &remainder) == 1.5
656 assert remainder == "junk"
658 Num.percent:
659 short: format as a percentage
660 description: >
661 Convert a number into a percentage text with a percent sign.
662 return:
663 type: 'Text'
664 description: >
665 A text representation of the number as a percentage with a percent sign.
666 args:
668 type: 'Num'
669 description: >
670 The number to be converted to a percent.
671 precision:
672 type: 'Num'
673 default: '0.01'
674 description: >
675 Round the percentage to this precision level.
676 example: |
677 assert (0.5).percent() == "50%"
678 assert (1./3.).percent(2) == "34%"
679 assert (1./3.).percent(precision=0.0001) == "33.3333%"
680 assert (1./3.).percent(precision=10.) == "30%"
682 Num.with_precision:
683 short: round to a given precision
684 description: >
685 Round a number to the given precision level (specified as `10`, `.1`, `.001` etc).
686 return:
687 type: 'Num'
688 description: >
689 The number, rounded to the given precision level.
690 args:
692 type: 'Num'
693 description: >
694 The number to be rounded to a given precision.
695 precision:
696 type: 'Num'
697 description: >
698 The precision to which the number should be rounded.
699 example: |
700 assert (0.1234567).with_precision(0.01) == 0.12
701 assert (123456.).with_precision(100) == 123500
702 assert (1234567.).with_precision(5) == 1234565
704 Num.rint:
705 short: round to nearest integer
706 description: >
707 Rounds a number to the nearest integer, with ties rounded to the nearest even integer.
708 return:
709 type: 'Num'
710 description: >
711 The nearest integer value of `x`.
712 args:
714 type: 'Num'
715 description: >
716 The number to be rounded.
717 example: |
718 assert (3.5).rint() == 4
719 assert (2.5).rint() == 2
721 Num.round:
722 short: round to nearest integer
723 description: >
724 Rounds a number to the nearest whole number integer.
725 return:
726 type: 'Num'
727 description: >
728 The nearest integer value of `x`.
729 args:
731 type: 'Num'
732 description: >
733 The number to be rounded.
734 example: |
735 assert (2.3).round() == 2
736 assert (2.7).round() == 3
738 Num.significand:
739 short: get mantissa
740 description: >
741 Extracts the significand (or mantissa) of a number.
742 return:
743 type: 'Num'
744 description: >
745 The significand of `x`.
746 args:
748 type: 'Num'
749 description: >
750 The number from which to extract the significand.
751 example: |
752 assert (1234.567).significand() == 1.2056318359375
754 Num.sin:
755 short: sine
756 description: >
757 Computes the sine of a number (angle in radians).
758 return:
759 type: 'Num'
760 description: >
761 The sine of `x`.
762 args:
764 type: 'Num'
765 description: >
766 The angle in radians.
767 example: |
768 assert (0.0).sin() == 0
770 Num.sinh:
771 short: hyperbolic sine
772 description: >
773 Computes the hyperbolic sine of a number.
774 return:
775 type: 'Num'
776 description: >
777 The hyperbolic sine of `x`.
778 args:
780 type: 'Num'
781 description: >
782 The number for which the hyperbolic sine is to be calculated.
783 example: |
784 assert (0.0).sinh() == 0
786 Num.sqrt:
787 short: square root
788 description: >
789 Computes the square root of a number.
790 return:
791 type: 'Num'
792 description: >
793 The square root of `x`.
794 args:
796 type: 'Num'
797 description: >
798 The number for which the square root is to be calculated.
799 example: |
800 assert (16.0).sqrt() == 4
802 Num.tan:
803 short: tangent
804 description: >
805 Computes the tangent of a number (angle in radians).
806 return:
807 type: 'Num'
808 description: >
809 The tangent of `x`.
810 args:
812 type: 'Num'
813 description: >
814 The angle in radians.
815 example: |
816 assert (0.0).tan() == 0
818 Num.tanh:
819 short: hyperbolic tangent
820 description: >
821 Computes the hyperbolic tangent of a number.
822 return:
823 type: 'Num'
824 description: >
825 The hyperbolic tangent of `x`.
826 args:
828 type: 'Num'
829 description: >
830 The number for which the hyperbolic tangent is to be calculated.
831 example: |
832 assert (0.0).tanh() == 0
834 Num.tgamma:
835 short: "true gamma function"
836 description: >
837 Computes the gamma function of a number.
838 return:
839 type: 'Num'
840 description: >
841 The gamma function of `x`.
842 args:
844 type: 'Num'
845 description: >
846 The number for which the gamma function is to be calculated.
847 example: |
848 assert (1.0).tgamma() == 1
850 Num.trunc:
851 short: truncate a number
852 description: >
853 Truncates a number to the nearest integer towards zero.
854 return:
855 type: 'Num'
856 description: >
857 The integer part of `x` towards zero.
858 args:
860 type: 'Num'
861 description: >
862 The number to be truncated.
863 example: |
864 assert (3.7).trunc() == 3
865 assert (-3.7).trunc() == -3
867 Num.y0:
868 short: Bessel function
869 description: >
870 Computes the Bessel function of the second kind of order 0.
871 return:
872 type: 'Num'
873 description: >
874 The Bessel function of the second kind of order 0 of `x`.
875 args:
877 type: 'Num'
878 description: >
879 The number for which the Bessel function is to be calculated.
880 example: |
881 assert (1.0).y0().near(0.08825696421567698)
883 Num.y1:
884 short: Bessel function
885 description: >
886 Computes the Bessel function of the second kind of order 1.
887 return:
888 type: 'Num'
889 description: >
890 The Bessel function of the second kind of order 1 of `x`.
891 args:
893 type: 'Num'
894 description: >
895 The number for which the Bessel function is to be calculated.
896 example: |
897 assert (1.0).y1().near(-0.7812128213002887)
900 Num.1_PI:
901 short: 1/pi
902 type: Num
903 description: >
904 The constant $\frac{1}{\pi}$.
905 Num.2_PI:
906 short: 2*pi
907 type: Num
908 description: >
909 The constant $2 \times \pi$.
910 Num.2_SQRTPI:
911 short: 2*sqrt(pi)
912 type: Num
913 description: >
914 The constant $2 \times \sqrt{\pi}$.
915 Num.E:
916 short: Euler's constant
917 type: Num
918 description: >
919 The base of the natural logarithm ($e$).
920 Num.INF:
921 short: infinity
922 type: Num
923 description: >
924 Positive infinity.
925 Num.LN10:
926 short: log(10)
927 type: Num
928 description: >
929 The natural logarithm of 10.
930 Num.LN2:
931 short: log(2)
932 type: Num
933 description: >
934 The natural logarithm of 2.
935 Num.LOG2E:
936 short: log_2(e)
937 type: Num
938 description: >
939 The base 2 logarithm of $e$
940 Num.PI:
941 short: pi
942 type: Num
943 description: >
944 Pi ($\pi$).
945 Num.PI_2:
946 short: pi/2
947 type: Num
948 description: >
949 $\frac{\pi}{2}$
950 Num.PI_4:
951 short: pi/4
952 type: Num
953 description: >
954 $\frac{\pi}{4}$
955 Num.SQRT1_2:
956 short: sqrt(1/2)
957 type: Num
958 description: >
959 $\sqrt{\frac{1}{2}}$
960 Num.SQRT2:
961 short: sqrt(2)
962 type: Num
963 description: >
964 $\sqrt{2}$
965 Num.TAU:
966 short: 2*pi
967 type: Num
968 description: >
969 Tau ($2 \times \pi$)