(969 lines)
4 Calculates the absolute value of a number.8 The absolute value of `n`.13 The number whose absolute value is to be computed.15 assert (-3.5).abs() == 3.520 Computes the arc cosine of a number.24 The arc cosine of `x` in radians.29 The number for which the arc cosine is to be calculated.31 assert (0.0).acos().near(1.5707963267948966)36 Computes the inverse hyperbolic cosine of a number.40 The inverse hyperbolic cosine of `x`.45 The number for which the inverse hyperbolic cosine is to be calculated.47 assert (1.0).acosh() == 052 Computes the arc sine of a number.56 The arc sine of `x` in radians.61 The number for which the arc sine is to be calculated.63 assert (0.5).asin().near(0.5235987755982989)68 Computes the inverse hyperbolic sine of a number.72 The inverse hyperbolic sine of `x`.77 The number for which the inverse hyperbolic sine is to be calculated.79 assert (0.0).asinh() == 084 Computes the arc tangent of a number.88 The arc tangent of `x` in radians.93 The number for which the arc tangent is to be calculated.95 assert (1.0).atan().near(0.7853981633974483)100 Computes the arc tangent of the quotient of two numbers.104 The arc tangent of `x/y` in radians.109 The numerator.113 The denominator.115 assert Num.atan2(1, 1).near(0.7853981633974483)120 Computes the inverse hyperbolic tangent of a number.124 The inverse hyperbolic tangent of `x`.129 The number for which the inverse hyperbolic tangent is to be calculated.131 assert (0.5).atanh().near(0.5493061443340549)136 Computes the cube root of a number.140 The cube root of `x`.145 The number for which the cube root is to be calculated.147 assert (27.0).cbrt() == 3152 Rounds a number up to the nearest integer.156 The smallest integer greater than or equal to `x`.161 The number to be rounded up.163 assert (3.2).ceil() == 4168 Returns the given number clamped between two values so that it is within169 that range.173 The first argument clamped between the other two arguments.178 The number to clamp.182 The lowest value the result can take.186 The highest value the result can take.188 assert (2.5).clamped(5.5, 10.5) == 5.5193 Copies the sign of one number to another.197 A number with the magnitude of `x` and the sign of `y`.202 The number whose magnitude will be copied.206 The number whose sign will be copied.208 assert (3.0).copysign(-1) == -3213 Computes the cosine of a number (angle in radians).217 The cosine of `x`.222 The angle in radians.224 assert (0.0).cos() == 1229 Computes the hyperbolic cosine of a number.233 The hyperbolic cosine of `x`.238 The number for which the hyperbolic cosine is to be calculated.240 assert (0.0).cosh() == 1245 Computes the error function of a number.249 The error function of `x`.254 The number for which the error function is to be calculated.256 assert (0.0).erf() == 0261 Computes the complementary error function of a number.265 The complementary error function of `x`.270 The number for which the complementary error function is to be calculated.272 assert (0.0).erfc() == 1277 Computes the exponential function $e^x$ for a number.281 The value of $e^x$.286 The exponent.288 assert (1.0).exp().near(2.718281828459045)293 Computes $2^x$ for a number.297 The value of $2^x$.302 The exponent.304 assert (3.0).exp2() == 8309 Computes $e^x - 1$ for a number.313 The value of $e^x - 1$.318 The exponent.320 assert (1.0).expm1().near(1.7182818284590453)325 Computes the positive difference between two numbers.329 The positive difference $\max(0, x - y)$.334 The first number.338 The second number.340 assert (5.0).fdim(3) == 2345 Rounds a number down to the nearest integer.349 The largest integer less than or equal to `x`.354 The number to be rounded down.356 assert (3.7).floor() == 3361 Computes the Euclidean norm, $\sqrt{x^2 + y^2}$, of two numbers.365 The Euclidean norm of `x` and `y`.370 The first number.374 The second number.376 assert Num.hypot(3, 4) == 5381 Checks if a number is finite.385 `yes` if `n` is finite, `no` otherwise.390 The number to be checked.392 assert (1.0).isfinite() == yes393 assert Num.INF.isfinite() == no398 Determines if a number is between two numbers (inclusive).402 `yes` if `a <= x and x <= b` or `b <= x and x <= a`, otherwise `no`407 The integer to be checked.411 One end of the range to check (inclusive).415 The other end of the range to check (inclusive).417 assert (7.5).is_between(1, 10) == yes418 assert (7.5).is_between(10, 1) == yes419 assert (7.5).is_between(100, 200) == no420 assert (7.5).is_between(1, 7.5) == yes425 Checks if a number is infinite.429 `yes` if `n` is infinite, `no` otherwise.434 The number to be checked.436 assert Num.INF.isinf() == yes437 assert (1.0).isinf() == no442 Computes the Bessel function of the first kind of order 0.446 The Bessel function of the first kind of order 0 of `x`.451 The number for which the Bessel function is to be calculated.453 assert (0.0).j0() == 1458 Computes the Bessel function of the first kind of order 1.462 The Bessel function of the first kind of order 1 of `x`.467 The number for which the Bessel function is to be calculated.469 assert (0.0).j1() == 0474 Computes the natural logarithm (base $e$) of a number.478 The natural logarithm of `x`.483 The number for which the natural logarithm is to be calculated.485 assert Num.E.log() == 1490 Computes the base-10 logarithm of a number.494 The base-10 logarithm of `x`.499 The number for which the base-10 logarithm is to be calculated.501 assert (100.0).log10() == 2506 Computes $\log(1 + x)$ for a number.510 The value of $\log(1 + x)$.515 The number for which $\log(1 + x)$ is to be calculated.517 assert (1.0).log1p().near(0.6931471805599453)522 Computes the base-2 logarithm of a number.526 The base-2 logarithm of `x`.531 The number for which the base-2 logarithm is to be calculated.533 assert (8.0).log2() == 3538 Computes the binary exponent (base-2 logarithm) of a number.542 The binary exponent of `x`.547 The number for which the binary exponent is to be calculated.549 assert (8.0).logb() == 3554 Interpolates between two numbers based on a given amount.558 The interpolated number between `x` and `y` based on `amount`.563 The interpolation factor (between `0` and `1`).567 The starting number.571 The ending number.573 assert (0.5).mix(10, 20) == 15574 assert (0.25).mix(10, 20) == 12.5579 Checks if two numbers are approximately equal within specified tolerances. If580 two numbers are within an absolute difference or the ratio between the two is581 small enough, they are considered near each other.585 `yes` if `x` and `y` are approximately equal within the specified tolerances, `no` otherwise.590 The first number.594 The second number.599 The relative tolerance. Default is `1e-9`.604 The absolute tolerance. Default is `1e-9`.606 assert (1.0).near(1.000000001) == yes607 assert (100.0).near(110, ratio=0.1) == yes608 assert (5.0).near(5.1, min_epsilon=0.1) == yes613 Computes the next representable value after a given number towards a specified direction.617 The next representable value after `x` in the direction of `y`.622 The starting number.626 The direction towards which to find the next representable value.628 assert (1.0).nextafter(1.1) == 1.0000000000000002633 Converts a text representation of a number into a floating-point number.637 The number represented by the text or `none` if the entire text can't be parsed638 as a number.643 The text containing the number.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.651 assert Num.parse("3.14") == 3.14652 assert Num.parse("1e3") == 1000653 assert Num.parse("1.5junk") == none654 remainder : Text655 assert Num.parse("1.5junk", &remainder) == 1.5656 assert remainder == "junk"661 Convert a number into a percentage text with a percent sign.665 A text representation of the number as a percentage with a percent sign.670 The number to be converted to a percent.675 Round the percentage to this precision level.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%"685 Round a number to the given precision level (specified as `10`, `.1`, `.001` etc).689 The number, rounded to the given precision level.694 The number to be rounded to a given precision.698 The precision to which the number should be rounded.700 assert (0.1234567).with_precision(0.01) == 0.12701 assert (123456.).with_precision(100) == 123500702 assert (1234567.).with_precision(5) == 1234565707 Rounds a number to the nearest integer, with ties rounded to the nearest even integer.711 The nearest integer value of `x`.716 The number to be rounded.718 assert (3.5).rint() == 4719 assert (2.5).rint() == 2724 Rounds a number to the nearest whole number integer.728 The nearest integer value of `x`.733 The number to be rounded.735 assert (2.3).round() == 2736 assert (2.7).round() == 3741 Extracts the significand (or mantissa) of a number.745 The significand of `x`.750 The number from which to extract the significand.752 assert (1234.567).significand() == 1.2056318359375757 Computes the sine of a number (angle in radians).761 The sine of `x`.766 The angle in radians.768 assert (0.0).sin() == 0773 Computes the hyperbolic sine of a number.777 The hyperbolic sine of `x`.782 The number for which the hyperbolic sine is to be calculated.784 assert (0.0).sinh() == 0789 Computes the square root of a number.793 The square root of `x`.798 The number for which the square root is to be calculated.800 assert (16.0).sqrt() == 4805 Computes the tangent of a number (angle in radians).809 The tangent of `x`.814 The angle in radians.816 assert (0.0).tan() == 0821 Computes the hyperbolic tangent of a number.825 The hyperbolic tangent of `x`.830 The number for which the hyperbolic tangent is to be calculated.832 assert (0.0).tanh() == 0837 Computes the gamma function of a number.841 The gamma function of `x`.846 The number for which the gamma function is to be calculated.848 assert (1.0).tgamma() == 1853 Truncates a number to the nearest integer towards zero.857 The integer part of `x` towards zero.862 The number to be truncated.864 assert (3.7).trunc() == 3865 assert (-3.7).trunc() == -3870 Computes the Bessel function of the second kind of order 0.874 The Bessel function of the second kind of order 0 of `x`.879 The number for which the Bessel function is to be calculated.881 assert (1.0).y0().near(0.08825696421567698)886 Computes the Bessel function of the second kind of order 1.890 The Bessel function of the second kind of order 1 of `x`.895 The number for which the Bessel function is to be calculated.897 assert (1.0).y1().near(-0.7812128213002887)904 The constant $\frac{1}{\pi}$.909 The constant $2 \times \pi$.914 The constant $2 \times \sqrt{\pi}$.919 The base of the natural logarithm ($e$).924 Positive infinity.929 The natural logarithm of 10.934 The natural logarithm of 2.939 The base 2 logarithm of $e$944 Pi ($\pi$).949 $\frac{\pi}{2}$954 $\frac{\pi}{4}$959 $\sqrt{\frac{1}{2}}$964 $\sqrt{2}$969 Tau ($2 \times \pi$)