|Number| -> Number
Returns the absolute value of the number.
-1.abs()
# -> 1
1.abs()
# -> 1
|Number| -> Float
Returns the arc cosine of the number. acos
is the inverse function of cos
.
from number import pi
assert_near 0.acos(), pi / 2
assert_eq 1.acos(), 0
|Number| -> Float
Returns the inverse hyperbolic cosine of the number.
assert 0.acosh().is_nan()
assert_eq 1.acosh(), 0
assert_near 2.acosh(), 1.3169578969248166
|Integer, Integer| -> Integer
Returns the bitwise combination of two integers, where a 1
in both input
positions produces a 1
in corresponding output positions.
0b1010.and 0b1100
# 0b1000
# -> 8
|Number| -> Float
Returns the arc sine of the number. asin
is the inverse function of sin
.
from number import pi
assert_eq 0.asin(), 0
assert_near 1.asin(), pi / 2
|Number| -> Float
Returns the inverse hyperbolic sine of the number.
assert_eq 0.asinh(), 0
assert_near 1.asinh(), 0.8813735870195429
|Number| -> Float
Returns the arc tangent of the number. atan
is the inverse function of tan
.
from number import pi
assert_eq 0.atan(), 0
assert_near 1.atan(), pi / 4
|Number| -> Float
Returns the inverse hyperbolic tangent of the number.
-1.atanh()
# -> -inf
0.atanh()
# -> 0.0
1.atanh()
# -> inf
|Number, Number| -> Float
Returns the arc tangent of y
and x
in radians, using the signs of y
and
x
to determine the correct quadrant.
from number import pi
x, y = 1, 1
assert_near y.atan2(x), pi / 4
assert_near y.atan2(-x), pi - pi / 4
|Number| -> Integer
Returns the integer that's greater than or equal to the input.
0.5.ceil()
# -> 1
2.ceil()
# -> 2
-0.5.ceil()
# -> 0
|Number, Number, Number| -> Number
Returns the first number restricted to the range defined by the second and third numbers.
0.clamp 1, 2
# -> 1
1.5.clamp 1, 2
# -> 1.5
3.0.clamp 1, 2
# -> 2
|Number| -> Float
Returns the cosine of the number.
0.cos()
# -> 1.0
number.pi.cos()
# -> -1.0
|Number| -> Float
Returns the hyperbolic cosine of the number.
assert_eq 0.cosh(), 1
assert_near 1.cosh(), 1.5430806348152437
|Number| -> Float
Converts radians into degrees.
from number import pi, tau
pi.degrees()
# -> 180.0
tau.degrees()
# -> 360.0
Float
Provides the e
constant.
|Number| -> Float
Returns the result of applying the exponential function,
equivalent to calling e.pow x
.
assert_eq 0.exp(), 1
assert_eq 1.exp(), number.e
|Number| -> Float
Returns the result of applying the base-2 exponential function,
equivalent to calling 2.pow x
.
1.exp2()
# -> 2.0
3.exp2()
# -> 8.0
|Integer| -> Integer
Returns the input with its bits 'flipped', i.e. 1
=> 0
, and 0
=> 1
.
1.flip_bits()
# -> -2
|Number| -> Integer
Returns the integer that's less than or equal to the input.
0.5.floor()
# -> 0
2.floor()
# -> 2
-0.5.floor()
# -> -1
Float
Provides the ∞
constant.
|Number| -> Bool
Returns true if the number is NaN
.
1.is_nan()
# -> false
(0 / 0).is_nan()
# -> true
|a: Number, b: Number, t: Number| -> Float
Linearly interpolates between a
and b
using the interpolation factor t
.
The range (a
-> b
) corresponds to the value range of (0
-> 1
) for t
.
e.g.
t
== 0
, the result is equal to a
.t
== 1
, the result is equal to b
.t
, the result is a proportional mix of a
and b
.t
outside of (0
-> 1
) will extrapolate from the (a
-> b
)
range.a, b = 1, 2
a.lerp b, 0
# -> 1
a.lerp b, 0.5
# -> 1.5
a.lerp b, 1
# -> 2
a.lerp b, -0.5
# -> 0.5
a.lerp b, 1.5
# -> 2.5
|Number| -> Float
Returns the natural logarithm of the number.
1.ln()
# -> 0.0
number.e.ln()
# -> 1.0
|Number| -> Float
Returns the base-2 logarithm of the number.
2.log2()
# -> 1.0
4.log2()
# -> 2.0
|Number| -> Float
Returns the base-10 logarithm of the number.
10.log10()
# -> 1.0
100.log10()
# -> 2.0
|Number, Number| -> Number
Returns the larger of the two numbers.
1.max 2
# -> 2
4.5.max 3
# -> 4.5
|Number, Number| -> Number
Returns the smaller of the two numbers.
1.min 2
# -> 1
4.5.min 3
# -> 3
Float
Provides the NaN
(Not a Number) constant.
Float
Provides the -∞
constant.
|Integer, Integer| -> Integer
Returns the bitwise combination of two integers, where a 1
in either input
positions produces a 1
in corresponding output positions.
0b1010.or 0b1100
# 0b1110
# -> 14
Float
Provides the π
constant.
Float
Provides the π
constant divided by 2
.
Float
Provides the π
constant divided by 4
.
|Number, Number| -> Number
Returns the result of raising the first number to the power of the second.
2.pow 3
# -> 8
|Number| -> Float
Converts degrees into radians.
from number import pi
assert_near 90.radians(), pi / 2
assert_near 360.radians(), pi * 2
|Number| -> Float
Returns the reciprocal of the number, i.e. 1 / x
.
2.recip()
# -> 0.5
|Number| -> Integer
Returns the nearest integer to the input number. Half-way values round away from zero.
0.5.round()
# -> 1
2.round()
# -> 2
-0.5.round()
# -> -1
|Integer, Integer| -> Integer
Returns the result of shifting the bits of the first number to the left by the amount specified by the second number.
The shift amount must be greater than or equal to 0
.
0b1010.shift_left 2
# 0b101000
# -> 40
|Integer, Integer| -> Integer
Returns the result of shifting the bits of the first number to the right by the amount specified by the second number.
The shift amount must be greater than or equal to 0
.
0b1010.shift_right 2
# 0b0010
# -> 2
|Number| -> Float
Returns the sine of the number.
from number import pi
(pi * 0.5).sin()
# -> 1.0
(pi * 1.5).sin()
# -> -1.0
|Number| -> Float
Returns the hyperbolic sine of the number.
assert_eq 0.sinh(), 0
assert_near 1.sinh(), 1.1752011936438014
|Number| -> Float
Returns the square root of the number.
64.sqrt()
# -> 8.0
|Number| -> Float
Returns the tangent of the number.
assert_eq 0.tan(), 0
assert_near 1.tan(), 1.557407724654902
|Number| -> Float
Returns the hyperbolic tangent of the number.
assert_near 1.tanh(), 1.sinh() / 1.cosh()
Float
Provides the τ
constant, equivalent to 2π
.
|Number| -> Float
Returns the number as a Float
.
1.to_float()
# -> 1.0
|Number| -> Integer
Converts a Number into an integer by removing its fractional part.
This is often called trunc
in other languages.
2.9.to_int()
# -> 2
1.5.to_int()
# -> 1
-0.5.to_int()
# -> 0
-1.9.to_int()
# -> -1
|Integer, Integer| -> Integer
Returns the bitwise combination of two integers,
where a 1
in one (and only one) of the input positions
produces a 1
in corresponding output positions.
0b1010.xor 0b1100
# 0b0110
# -> 6