Improve documentation of int
This commit is contained in:
parent
cd491c6e47
commit
0f3197501e
|
@ -1,40 +1,38 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<class name="int" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
|
<class name="int" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
|
||||||
<brief_description>
|
<brief_description>
|
||||||
Integer built-in type.
|
Built-in integer Variant type.
|
||||||
</brief_description>
|
</brief_description>
|
||||||
<description>
|
<description>
|
||||||
Signed 64-bit integer type.
|
Signed 64-bit integer type. This means that it can take values from [code]-2^63[/code] to [code]2^63 - 1[/code], i.e. from [code]-9223372036854775808[/code] to [code]9223372036854775807[/code]. When it exceeds these bounds, it will wrap around.
|
||||||
It can take values in the interval [code][-2^63, 2^63 - 1][/code], i.e. [code][-9223372036854775808, 9223372036854775807][/code]. Exceeding those bounds will wrap around.
|
[int]s can be automatically converted to [float]s when necessary, for example when passing them as arguments in functions. The [float] will be as close to the original integer as possible.
|
||||||
[int] is a [Variant] type, and will thus be used when assigning an integer value to a [Variant]. It can also be enforced with the [code]: int[/code] type hint.
|
Likewise, [float]s can be automatically converted into [int]s. This will truncate the [float], discarding anything after the floating point.
|
||||||
|
[b]Note:[/b] In a boolean context, an [int] will evaluate to [code]false[/code] if it equals [code]0[/code], and to [code]true[/code] otherwise.
|
||||||
[codeblocks]
|
[codeblocks]
|
||||||
[gdscript]
|
[gdscript]
|
||||||
var my_variant = 0 # int, value 0.
|
var x: int = 1 # x is 1
|
||||||
my_variant += 4.2 # float, value 4.2.
|
x = 4.2 # x is 4, because 4.2 gets truncated
|
||||||
var my_int: int = 1 # int, value 1.
|
var max_int = 9223372036854775807 # Biggest value an int can store
|
||||||
my_int = 4.2 # int, value 4, the right value is implicitly cast to int.
|
max_int += 1 # max_int is -9223372036854775808, because it wrapped around
|
||||||
my_int = int("6.7") # int, value 6, the String is explicitly cast with int.
|
|
||||||
var max_int = 9223372036854775807
|
|
||||||
print(max_int) # 9223372036854775807, OK.
|
|
||||||
max_int += 1
|
|
||||||
print(max_int) # -9223372036854775808, we overflowed and wrapped around.
|
|
||||||
[/gdscript]
|
[/gdscript]
|
||||||
[csharp]
|
[csharp]
|
||||||
int myInt = (int)"6.7".ToFloat(); // int, value 6, the String is explicitly cast with int.
|
int x = 1; // x is 1
|
||||||
// We have to use `long` here, because GDSript's `int`
|
x = 4.2; // x is 4, because 4.2 gets truncated
|
||||||
// is 64 bits long while C#'s `int` is only 32 bits.
|
// We use long below, because GDScript's int is 64-bit while C#'s int is 32-bit.
|
||||||
long maxInt = 9223372036854775807;
|
long maxLong = 9223372036854775807; // Biggest value a long can store
|
||||||
GD.Print(maxInt); // 9223372036854775807, OK.
|
maxLong++; // maxLong is now -9223372036854775808, because it wrapped around.
|
||||||
maxInt++;
|
|
||||||
GD.Print(maxInt); // -9223372036854775808, we overflowed and wrapped around.
|
|
||||||
|
|
||||||
// Alternatively, if we used C#'s 32-bit `int` type, the maximum value is much smaller:
|
// Alternatively with C#'s 32-bit int type, which has a smaller maximum value.
|
||||||
int halfInt = 2147483647;
|
int maxInt = 2147483647; // Biggest value an int can store
|
||||||
GD.Print(halfInt); // 2147483647, OK.
|
maxInt++; // maxInt is now -2147483648, because it wrapped around
|
||||||
halfInt++;
|
|
||||||
GD.Print(halfInt); // -2147483648, we overflowed and wrapped around.
|
|
||||||
[/csharp]
|
[/csharp]
|
||||||
[/codeblocks]
|
[/codeblocks]
|
||||||
|
In GDScript, you can use the [code]0b[/code] literal for binary representation, the [code]0x[/code] literal for hexadecimal representation, and the [code]_[/code] symbol to separate long numbers and improve readability.
|
||||||
|
[codeblock]
|
||||||
|
var x = 0b1001 # x is 9
|
||||||
|
var y = 0xF5 # y is 245
|
||||||
|
var z = 10_000_000 # z is 10000000
|
||||||
|
[/codeblock]
|
||||||
</description>
|
</description>
|
||||||
<tutorials>
|
<tutorials>
|
||||||
</tutorials>
|
</tutorials>
|
||||||
|
@ -42,7 +40,7 @@
|
||||||
<constructor name="int">
|
<constructor name="int">
|
||||||
<return type="int" />
|
<return type="int" />
|
||||||
<description>
|
<description>
|
||||||
Constructs a default-initialized [int] set to [code]0[/code].
|
Constructs an [int] set to [code]0[/code].
|
||||||
</description>
|
</description>
|
||||||
</constructor>
|
</constructor>
|
||||||
<constructor name="int">
|
<constructor name="int">
|
||||||
|
@ -56,21 +54,21 @@
|
||||||
<return type="int" />
|
<return type="int" />
|
||||||
<param index="0" name="from" type="String" />
|
<param index="0" name="from" type="String" />
|
||||||
<description>
|
<description>
|
||||||
Converts a [String] to an [int], following the same rules as [method String.to_int].
|
Constructs a new [int] from a [String], following the same rules as [method String.to_int].
|
||||||
</description>
|
</description>
|
||||||
</constructor>
|
</constructor>
|
||||||
<constructor name="int">
|
<constructor name="int">
|
||||||
<return type="int" />
|
<return type="int" />
|
||||||
<param index="0" name="from" type="bool" />
|
<param index="0" name="from" type="bool" />
|
||||||
<description>
|
<description>
|
||||||
Cast a [bool] value to an integer value, [code]int(true)[/code] will be equals to 1 and [code]int(false)[/code] will be equals to 0.
|
Constructs a new [int] from a [bool]. [code]true[/code] is converted to [code]1[/code] and [code]false[/code] is converted to [code]0[/code].
|
||||||
</description>
|
</description>
|
||||||
</constructor>
|
</constructor>
|
||||||
<constructor name="int">
|
<constructor name="int">
|
||||||
<return type="int" />
|
<return type="int" />
|
||||||
<param index="0" name="from" type="float" />
|
<param index="0" name="from" type="float" />
|
||||||
<description>
|
<description>
|
||||||
Cast a float value to an integer value, this method simply removes the number fractions (i.e. rounds [param from] towards zero), so for example [code]int(2.7)[/code] will be equals to 2, [code]int(0.1)[/code] will be equals to 0 and [code]int(-2.7)[/code] will be equals to -2. This operation is also called truncation.
|
Constructs a new [int] from a [float]. This will truncate the [float], discarding anything after the floating point.
|
||||||
</description>
|
</description>
|
||||||
</constructor>
|
</constructor>
|
||||||
</constructors>
|
</constructors>
|
||||||
|
@ -79,25 +77,25 @@
|
||||||
<return type="bool" />
|
<return type="bool" />
|
||||||
<param index="0" name="right" type="float" />
|
<param index="0" name="right" type="float" />
|
||||||
<description>
|
<description>
|
||||||
Returns [code]true[/code] if this [int] is not equivalent to the given [float].
|
Returns [code]true[/code] if the [int] is not equivalent to the [float].
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator !=">
|
<operator name="operator !=">
|
||||||
<return type="bool" />
|
<return type="bool" />
|
||||||
<param index="0" name="right" type="int" />
|
<param index="0" name="right" type="int" />
|
||||||
<description>
|
<description>
|
||||||
Returns [code]true[/code] if the integers are not equal.
|
Returns [code]true[/code] if the [int]s are not equal.
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator %">
|
<operator name="operator %">
|
||||||
<return type="int" />
|
<return type="int" />
|
||||||
<param index="0" name="right" type="int" />
|
<param index="0" name="right" type="int" />
|
||||||
<description>
|
<description>
|
||||||
Returns the remainder after dividing two integers. This operation uses truncated division, which is often not desired as it does not work well with negative numbers. Consider using [method @GlobalScope.posmod] instead if you want to handle negative numbers.
|
Returns the remainder after dividing two [int]s. Uses truncated division, which returns a negative number if the dividend is negative. If this is not desired, consider using [method @GlobalScope.posmod].
|
||||||
[codeblock]
|
[codeblock]
|
||||||
print(5 % 2) # 1
|
print(6 % 2) # Prints 0
|
||||||
print(12 % 4) # 0
|
print(11 % 4) # Prints 3
|
||||||
print(-5 % 3) # -2
|
print(-5 % 3) # Prints -2
|
||||||
[/codeblock]
|
[/codeblock]
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
|
@ -105,17 +103,16 @@
|
||||||
<return type="int" />
|
<return type="int" />
|
||||||
<param index="0" name="right" type="int" />
|
<param index="0" name="right" type="int" />
|
||||||
<description>
|
<description>
|
||||||
Returns the result of bitwise [code]AND[/code] operation for two integers.
|
Performs the bitwise [code]AND[/code] operation.
|
||||||
[codeblock]
|
[codeblock]
|
||||||
print(3 & 1) # 1
|
print(0b1100 & 0b1010) # Prints 8 (binary 1000)
|
||||||
print(11 & 3) # 3
|
|
||||||
[/codeblock]
|
[/codeblock]
|
||||||
It's useful to retrieve binary flags from a variable.
|
This is useful for retrieving binary flags from a variable.
|
||||||
[codeblock]
|
[codeblock]
|
||||||
var flags = 5
|
var flags = 0b101
|
||||||
# Do something if the first bit is enabled.
|
# Check if the first or second bit are enabled.
|
||||||
if flags & 1:
|
if flags & 0b011:
|
||||||
do_stuff()
|
do_stuff() # This line will run.
|
||||||
[/codeblock]
|
[/codeblock]
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
|
@ -123,23 +120,23 @@
|
||||||
<return type="Color" />
|
<return type="Color" />
|
||||||
<param index="0" name="right" type="Color" />
|
<param index="0" name="right" type="Color" />
|
||||||
<description>
|
<description>
|
||||||
Multiplies each component of the [Color] by the given [int].
|
Multiplies each component of the [Color] by the [int].
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator *">
|
<operator name="operator *">
|
||||||
<return type="Quaternion" />
|
<return type="Quaternion" />
|
||||||
<param index="0" name="right" type="Quaternion" />
|
<param index="0" name="right" type="Quaternion" />
|
||||||
<description>
|
<description>
|
||||||
Multiplies each component of the [Quaternion] by the given [int]. This operation is not meaningful on its own, but it can be used as a part of a larger expression.
|
Multiplies each component of the [Quaternion] by the [int]. This operation is not meaningful on its own, but it can be used as a part of a larger expression.
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator *">
|
<operator name="operator *">
|
||||||
<return type="Vector2" />
|
<return type="Vector2" />
|
||||||
<param index="0" name="right" type="Vector2" />
|
<param index="0" name="right" type="Vector2" />
|
||||||
<description>
|
<description>
|
||||||
Multiplies each component of the [Vector2] by the given [int].
|
Multiplies each component of the [Vector2] by the [int].
|
||||||
[codeblock]
|
[codeblock]
|
||||||
print(2 * Vector2(1, 1)) # Vector2(2, 2)
|
print(2 * Vector2(1, 4)) # Prints (2, 8)
|
||||||
[/codeblock]
|
[/codeblock]
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
|
@ -147,49 +144,49 @@
|
||||||
<return type="Vector2i" />
|
<return type="Vector2i" />
|
||||||
<param index="0" name="right" type="Vector2i" />
|
<param index="0" name="right" type="Vector2i" />
|
||||||
<description>
|
<description>
|
||||||
Multiplies each component of the [Vector2i] by the given [int].
|
Multiplies each component of the [Vector2i] by the [int].
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator *">
|
<operator name="operator *">
|
||||||
<return type="Vector3" />
|
<return type="Vector3" />
|
||||||
<param index="0" name="right" type="Vector3" />
|
<param index="0" name="right" type="Vector3" />
|
||||||
<description>
|
<description>
|
||||||
Multiplies each component of the [Vector3] by the given [int].
|
Multiplies each component of the [Vector3] by the [int].
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator *">
|
<operator name="operator *">
|
||||||
<return type="Vector3i" />
|
<return type="Vector3i" />
|
||||||
<param index="0" name="right" type="Vector3i" />
|
<param index="0" name="right" type="Vector3i" />
|
||||||
<description>
|
<description>
|
||||||
Multiplies each component of the [Vector3i] by the given [int].
|
Multiplies each component of the [Vector3i] by the [int].
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator *">
|
<operator name="operator *">
|
||||||
<return type="Vector4" />
|
<return type="Vector4" />
|
||||||
<param index="0" name="right" type="Vector4" />
|
<param index="0" name="right" type="Vector4" />
|
||||||
<description>
|
<description>
|
||||||
Multiplies each component of the [Vector4] by the given [int].
|
Multiplies each component of the [Vector4] by the [int].
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator *">
|
<operator name="operator *">
|
||||||
<return type="Vector4i" />
|
<return type="Vector4i" />
|
||||||
<param index="0" name="right" type="Vector4i" />
|
<param index="0" name="right" type="Vector4i" />
|
||||||
<description>
|
<description>
|
||||||
Multiplies each component of the [Vector4i] by the given [int].
|
Multiplies each component of the [Vector4i] by the [int].
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator *">
|
<operator name="operator *">
|
||||||
<return type="float" />
|
<return type="float" />
|
||||||
<param index="0" name="right" type="float" />
|
<param index="0" name="right" type="float" />
|
||||||
<description>
|
<description>
|
||||||
Multiplies an [int] and a [float]. The result is a [float].
|
Multiplies the [float] by the [int]. The result is a [float].
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator *">
|
<operator name="operator *">
|
||||||
<return type="int" />
|
<return type="int" />
|
||||||
<param index="0" name="right" type="int" />
|
<param index="0" name="right" type="int" />
|
||||||
<description>
|
<description>
|
||||||
Multiplies two [int]s.
|
Multiplies the two [int]s.
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator **">
|
<operator name="operator **">
|
||||||
|
@ -198,7 +195,7 @@
|
||||||
<description>
|
<description>
|
||||||
Raises an [int] to a power of a [float]. The result is a [float].
|
Raises an [int] to a power of a [float]. The result is a [float].
|
||||||
[codeblock]
|
[codeblock]
|
||||||
print(8**0.25) # 1.68179283050743
|
print(2 ** 0.5) # Prints 1.4142135623731
|
||||||
[/codeblock]
|
[/codeblock]
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
|
@ -206,9 +203,9 @@
|
||||||
<return type="int" />
|
<return type="int" />
|
||||||
<param index="0" name="right" type="int" />
|
<param index="0" name="right" type="int" />
|
||||||
<description>
|
<description>
|
||||||
Raises an [int] to a power of a [int].
|
Raises the left [int] to a power of the right [int].
|
||||||
[codeblock]
|
[codeblock]
|
||||||
print(5**5) # 3125
|
print(3 ** 4) # Prints 81
|
||||||
[/codeblock]
|
[/codeblock]
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
|
@ -216,37 +213,37 @@
|
||||||
<return type="float" />
|
<return type="float" />
|
||||||
<param index="0" name="right" type="float" />
|
<param index="0" name="right" type="float" />
|
||||||
<description>
|
<description>
|
||||||
Adds an [int] and a [float]. The result is a [float].
|
Adds the [int] and the [float]. The result is a [float].
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator +">
|
<operator name="operator +">
|
||||||
<return type="int" />
|
<return type="int" />
|
||||||
<param index="0" name="right" type="int" />
|
<param index="0" name="right" type="int" />
|
||||||
<description>
|
<description>
|
||||||
Adds two integers.
|
Adds the two [int]s.
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator -">
|
<operator name="operator -">
|
||||||
<return type="float" />
|
<return type="float" />
|
||||||
<param index="0" name="right" type="float" />
|
<param index="0" name="right" type="float" />
|
||||||
<description>
|
<description>
|
||||||
Subtracts a [float] from an [int]. The result is a [float].
|
Subtracts the [float] from the [int]. The result is a [float].
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator -">
|
<operator name="operator -">
|
||||||
<return type="int" />
|
<return type="int" />
|
||||||
<param index="0" name="right" type="int" />
|
<param index="0" name="right" type="int" />
|
||||||
<description>
|
<description>
|
||||||
Subtracts two integers.
|
Subtracts the two [int]s.
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator /">
|
<operator name="operator /">
|
||||||
<return type="float" />
|
<return type="float" />
|
||||||
<param index="0" name="right" type="float" />
|
<param index="0" name="right" type="float" />
|
||||||
<description>
|
<description>
|
||||||
Divides an [int] by a [float]. The result is a [float].
|
Divides the [int] by the [float]. The result is a [float].
|
||||||
[codeblock]
|
[codeblock]
|
||||||
print(10 / 3.0) # 3.333...
|
print(10 / 3.0) # Prints 3.33333333333333
|
||||||
[/codeblock]
|
[/codeblock]
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
|
@ -254,10 +251,10 @@
|
||||||
<return type="int" />
|
<return type="int" />
|
||||||
<param index="0" name="right" type="int" />
|
<param index="0" name="right" type="int" />
|
||||||
<description>
|
<description>
|
||||||
Divides two integers. The decimal part of the result is discarded (truncated).
|
Divides the two [int]s. The result is an [int]. This will truncate the [float], discarding anything after the floating point.
|
||||||
[codeblock]
|
[codeblock]
|
||||||
print(10 / 2) # 5
|
print(6 / 2) # Prints 3
|
||||||
print(10 / 3) # 3
|
print(5 / 3) # Prints 1
|
||||||
[/codeblock]
|
[/codeblock]
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
|
@ -265,24 +262,24 @@
|
||||||
<return type="bool" />
|
<return type="bool" />
|
||||||
<param index="0" name="right" type="float" />
|
<param index="0" name="right" type="float" />
|
||||||
<description>
|
<description>
|
||||||
Returns [code]true[/code] if this [int] is less than the given [float].
|
Returns [code]true[/code] if the [int] is less than the [float].
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator <">
|
<operator name="operator <">
|
||||||
<return type="bool" />
|
<return type="bool" />
|
||||||
<param index="0" name="right" type="int" />
|
<param index="0" name="right" type="int" />
|
||||||
<description>
|
<description>
|
||||||
Returns [code]true[/code] if the left integer is less than the right one.
|
Returns [code]true[/code] if the left [int] is less than the right [int].
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator <<">
|
<operator name="operator <<">
|
||||||
<return type="int" />
|
<return type="int" />
|
||||||
<param index="0" name="right" type="int" />
|
<param index="0" name="right" type="int" />
|
||||||
<description>
|
<description>
|
||||||
Performs bitwise shift left operation on the integer. Effectively the same as multiplying by a power of 2.
|
Performs the bitwise shift left operation. Effectively the same as multiplying by a power of 2.
|
||||||
[codeblock]
|
[codeblock]
|
||||||
print(10 << 1) # 20
|
print(0b1010 << 1) # Prints 20 (binary 10100)
|
||||||
print(10 << 4) # 160
|
print(0b1010 << 3) # Prints 80 (binary 1010000)
|
||||||
[/codeblock]
|
[/codeblock]
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
|
@ -290,66 +287,66 @@
|
||||||
<return type="bool" />
|
<return type="bool" />
|
||||||
<param index="0" name="right" type="float" />
|
<param index="0" name="right" type="float" />
|
||||||
<description>
|
<description>
|
||||||
Returns [code]true[/code] if this [int] is less than or equal to the given [float].
|
Returns [code]true[/code] if the [int] is less than or equal to the [float].
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator <=">
|
<operator name="operator <=">
|
||||||
<return type="bool" />
|
<return type="bool" />
|
||||||
<param index="0" name="right" type="int" />
|
<param index="0" name="right" type="int" />
|
||||||
<description>
|
<description>
|
||||||
Returns [code]true[/code] if the left integer is less than or equal to the right one.
|
Returns [code]true[/code] if the left [int] is less than or equal to the right [int].
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator ==">
|
<operator name="operator ==">
|
||||||
<return type="bool" />
|
<return type="bool" />
|
||||||
<param index="0" name="right" type="float" />
|
<param index="0" name="right" type="float" />
|
||||||
<description>
|
<description>
|
||||||
Returns [code]true[/code] if the integer is equal to the given [float].
|
Returns [code]true[/code] if the [int] is equal to the [float].
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator ==">
|
<operator name="operator ==">
|
||||||
<return type="bool" />
|
<return type="bool" />
|
||||||
<param index="0" name="right" type="int" />
|
<param index="0" name="right" type="int" />
|
||||||
<description>
|
<description>
|
||||||
Returns [code]true[/code] if both integers are equal.
|
Returns [code]true[/code] if the two [int]s are equal.
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator >">
|
<operator name="operator >">
|
||||||
<return type="bool" />
|
<return type="bool" />
|
||||||
<param index="0" name="right" type="float" />
|
<param index="0" name="right" type="float" />
|
||||||
<description>
|
<description>
|
||||||
Returns [code]true[/code] if this [int] is greater than the given [float].
|
Returns [code]true[/code] if the [int] is greater than the [float].
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator >">
|
<operator name="operator >">
|
||||||
<return type="bool" />
|
<return type="bool" />
|
||||||
<param index="0" name="right" type="int" />
|
<param index="0" name="right" type="int" />
|
||||||
<description>
|
<description>
|
||||||
Returns [code]true[/code] if the left integer is greater than the right one.
|
Returns [code]true[/code] if the left [int] is greater than the right [int].
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator >=">
|
<operator name="operator >=">
|
||||||
<return type="bool" />
|
<return type="bool" />
|
||||||
<param index="0" name="right" type="float" />
|
<param index="0" name="right" type="float" />
|
||||||
<description>
|
<description>
|
||||||
Returns [code]true[/code] if this [int] is greater than or equal to the given [float].
|
Returns [code]true[/code] if the [int] is greater than or equal to the [float].
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator >=">
|
<operator name="operator >=">
|
||||||
<return type="bool" />
|
<return type="bool" />
|
||||||
<param index="0" name="right" type="int" />
|
<param index="0" name="right" type="int" />
|
||||||
<description>
|
<description>
|
||||||
Returns [code]true[/code] if the left integer is greater than or equal to the right one.
|
Returns [code]true[/code] if the left [int] is greater than or equal to the right [int].
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator >>">
|
<operator name="operator >>">
|
||||||
<return type="int" />
|
<return type="int" />
|
||||||
<param index="0" name="right" type="int" />
|
<param index="0" name="right" type="int" />
|
||||||
<description>
|
<description>
|
||||||
Performs bitwise shift right operation on the integer. Effectively the same as dividing by a power of 2.
|
Performs the bitwise shift right operation. Effectively the same as dividing by a power of 2.
|
||||||
[codeblock]
|
[codeblock]
|
||||||
print(10 >> 1) # 5
|
print(0b1010 >> 1) # Prints 5 (binary 101)
|
||||||
print(10 >> 2) # 2
|
print(0b1010 >> 2) # Prints 2 (binary 10)
|
||||||
[/codeblock]
|
[/codeblock]
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
|
@ -357,10 +354,9 @@
|
||||||
<return type="int" />
|
<return type="int" />
|
||||||
<param index="0" name="right" type="int" />
|
<param index="0" name="right" type="int" />
|
||||||
<description>
|
<description>
|
||||||
Returns the result of bitwise [code]XOR[/code] operation for two integers.
|
Performs the bitwise [code]XOR[/code] operation.
|
||||||
[codeblock]
|
[codeblock]
|
||||||
print(5 ^ 1) # 4
|
print(0b1100 ^ 0b1010) # Prints 6 (binary 110)
|
||||||
print(4 ^ 7) # 3
|
|
||||||
[/codeblock]
|
[/codeblock]
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
|
@ -380,27 +376,24 @@
|
||||||
<return type="int" />
|
<return type="int" />
|
||||||
<param index="0" name="right" type="int" />
|
<param index="0" name="right" type="int" />
|
||||||
<description>
|
<description>
|
||||||
Returns the result of bitwise [code]OR[/code] operation for two integers.
|
Performs the bitwise [code]OR[/code] operation.
|
||||||
[codeblock]
|
[codeblock]
|
||||||
print(2 | 4) # 6
|
print(0b1100 | 0b1010) # Prints 14 (binary 1110)
|
||||||
print(1 | 3) # 3
|
|
||||||
[/codeblock]
|
[/codeblock]
|
||||||
It's useful to store binary flags in a variable.
|
This is useful for storing binary flags in a variable.
|
||||||
[codeblock]
|
[codeblock]
|
||||||
var flags = 0
|
var flags = 0
|
||||||
# Turn first and third bit on.
|
flags |= 0b101 # Turn the first and third bits on.
|
||||||
flags |= 1
|
|
||||||
flags |= 4
|
|
||||||
[/codeblock]
|
[/codeblock]
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
<operator name="operator ~">
|
<operator name="operator ~">
|
||||||
<return type="int" />
|
<return type="int" />
|
||||||
<description>
|
<description>
|
||||||
Returns the result of bitwise [code]NOT[/code] operation for the integer. It's effectively equal to [code]-int + 1[/code].
|
Performs the bitwise [code]NOT[/code] operation on the [int]. Due to [url=https://en.wikipedia.org/wiki/Two%27s_complement/]2's complement[/url], it's effectively equal to [code]-(int + 1)[/code].
|
||||||
[codeblock]
|
[codeblock]
|
||||||
print(~4) # -3
|
print(~4) # Prints -5
|
||||||
print(~7) # -6
|
print(~(-7)) # Prints 6
|
||||||
[/codeblock]
|
[/codeblock]
|
||||||
</description>
|
</description>
|
||||||
</operator>
|
</operator>
|
||||||
|
|
Loading…
Reference in New Issue