In other languages: Čeština Deutsch Français 日本語 Polski Русский Українська 简体中文

Arithmetic combinator: Difference between revisions

From Official Factorio Wiki
Jump to navigation Jump to search
(added examples, full list of operations and corresponding symbols, description of how the each signal can be used)
 
(25 intermediate revisions by 9 users not shown)
Line 1: Line 1:
{{Languages}}
{{Languages}}
{{:Arithmetic combinator/infobox}}
{{:Infobox:Arithmetic combinator}}
The arithmetic combinator is part of the [[circuit network]] and one of three types of combinators available in the game (along with the [[constant combinator]] and [[decider combinator]]). Each arithmetic combinator can perform any one of the following mathematical operations on signals, and will show the corresponding symbol on its top:
The arithmetic combinator is part of the [[circuit network]] and one of four types of combinators available in the game (along with the [[constant combinator]], [[decider combinator]], and [[selector combinator]]). Each arithmetic combinator can perform any one of the following mathematical operations on signals, and will show the corresponding symbol on its top:
 
[[File:arith_combinator_anim.png]]


* addition (<span style="color:yellow">+</span>)
* addition (<span style="color:yellow">+</span>)
* subtraction (<span style="color:yellow">-</span>)
* subtraction (<span style="color:yellow"></span>)
* multiplication (<span style="color:yellow">*</span>)
* multiplication (<span style="color:yellow">*</span>)
* division (<span style="color:yellow">/</span>)
* division (<span style="color:yellow">/</span>)
* modulo (<span style="color:yellow">%</span>)
* modulo (<span style="color:yellow">%</span>)
* exponentiation (<span style="color:yellow">^</span>)
* exponentiation (<span style="color:yellow">^</span>)
* left bit shift (<span style="color:cyan"><<</span>)
* bit shift left (<span style="color:cyan"><<</span>)
* right bit shift (<span style="color:cyan">>></span>)
* bit shift right (<span style="color:cyan">>></span>)
* bitwise AND (<span style="color:cyan">&</span>)
* bitwise AND (<span style="color:cyan">&</span>)
* bitwise OR (<span style="color:cyan">|</span>)
* bitwise OR (<span style="color:cyan">|</span>)
Line 16: Line 18:


The arithmetic combinator accepts two input connections (red and green wires), and sends its output to both output connections. The input wires connect to the nubs on the left side of the sprite in the sidebar, while the outputs connect to the right side.
The arithmetic combinator accepts two input connections (red and green wires), and sends its output to both output connections. The input wires connect to the nubs on the left side of the sprite in the sidebar, while the outputs connect to the right side.
[[File:Arithmetic_combinator_gui.png|350px|GUI of the Arithmetic Combinator.]]<br />


== Function ==
== Function ==
Line 24: Line 28:
# The result of this operation is output as the selected output signal.
# The result of this operation is output as the selected output signal.


The left operand of the operation can be any single signal or the [[Virtual signals#Each|''each'' virtual signal]], and the right operand can be any single signal or a constant value.
The operands can be any single signal or a constant value. Up to one of the operands can be the [[Virtual signals#Each|''each'' virtual signal]].


If the left operand is a single signal, the output must be a single signal. The operation is performed on the values of the chosen left and right signals, and the result is sent to the output on the specified signal.
If neither operand is the ''each'' signal, the output must be a single signal. The operation is performed on the values of the chosen left and right signals, and the result is sent to the output on the specified signal.


If the left operand is the ''each'' signal, then the output can be a single signal or the ''each'' signal. If the output is the ''each'' signal, then the operation is performed individually on the value of each input signal along with the value of the right operand, and each result is sent to the output on the same signal. If the output is a single signal, the operation is done on each of the input signals, the individual results are all added together, and that result is sent to the output on the specified signal.
If one operand is the ''each'' signal, then the output can be a single signal or the ''each'' signal. If the output is the ''each'' signal, then the operation is performed individually on the value of each input signal along with the value of the other operand, and each result is sent to the output on the same signal. If the output is a single signal, the operation is done on each of the input signals, the individual results are all added together, and that result is sent to the output on the specified signal.


== Notes on operations ==
== Notes on operations ==
When using division, the result is truncated:
When using '''division''', the result is truncated:
* 21 / 10 = 2
* 21 / 10 = 2
* 19 / 10 = 1
* 19 / 10 = 1
* -21 / 10 = -2
* −21 / 10 = −2
* -19 / 10 = -1
* −19 / 10 = −1
* 21 / -10 = -2
* 21 / −10 = −2
* 19 / -10 = -1
* 19 / −10 = −1
* -21 / -10 = 2
* −21 / −10 = 2
* -19 / -10 = 1
* −19 / −10 = 1


Modulo, indicated using % as it is in most programming languages, is the remainder after division. For example, 13 % 3 is 1 (13 = 4 * 3 + 1). This can be used, for example, to separate out individual digits of a number for use in building visual indicators, along with division:
'''Modulo''', indicated using % as it is in most programming languages, is the remainder after division. For example, 13 % 3 is 1 (13 = 4 * 3 + 1). This can, for example, be combined with truncated division as described above to separate out individual digits of a number for use in building visual indicators:
* (24321 / 10000) % 10  = 2
* (24321 / 10000) % 10  = 2
* (24321 / 1000) % 10  = 4
* (24321 / 1000) % 10  = 4
Line 50: Line 54:
Negating the left operand of a modulo negates the result, while negating the right operand does nothing:
Negating the left operand of a modulo negates the result, while negating the right operand does nothing:
* 13 % 3 = 1
* 13 % 3 = 1
* 13 % -3 = 1
* 13 % −3 = 1
* -13 % 3 = -1
* −13 % 3 = −1
* -13 % -3 = -1
* −13 % −3 = −1
 
'''Bit shift right''' and '''Bit shift left''' deal with numbers in the [[:Wikipedia:Binary_number|binary]] representation. The 0's and 1's that make up a number are shifted in the specified direction which can result in a completely different number, due to the change in the binary value. The shift performed is called arithmetic shift, because it preserves the sign bit on bit shift right.
If shifting left, a 0 is inserted into the least significant bit (LSB), and the bit in the most significant bit (MSB) is lost.
If shifting right and the number is positive (MSB=0), a 0 is inserted into the MSB and the bit in the LSB is lost.
If shifting right and the number is negative (MSB=1), a 1 is inserted into the MSB to keep the sign and the bit in the LSB is lost.
[[File:Bitshiftleft.png|none|thumb|200px|Example of a 'bit shift left'.]] [[File:BitshiftRightZero.png|none|thumb|200px|Example of a 'bit shift right (positive number)'.]] [[File:BitshiftRightOne.png|none|thumb|200px|Example of a 'bit shift right (negative number)'.]]


== History ==
== History ==
{{history|2.0.7|
* Received a UI overhaul.
** Now displays input signals when configuring combinators.
** Signals used by combinators can now be filtered between red, green, or both.
}}
{{history|0.15.0|
{{history|0.15.0|
* Added Modulo, Power, Left Bit Shift, Right Bit Shift, Bitwise AND, Bitwise OR and Bitwise XOR to the Arithmetic Combinator.}}
* Added Modulo, Power, Left Bit Shift, Right Bit Shift, Bitwise AND, Bitwise OR and Bitwise XOR to the Arithmetic Combinator.}}
Line 77: Line 93:
==See Also==
==See Also==
*[[Decider combinator]]
*[[Decider combinator]]
*[[Selector combinator]]
*[[Constant combinator]]
*[[Constant combinator]]
*[[Tutorial:Combinator Tutorial|Combinator tutorial]]
*[[Tutorial:Combinator tutorial|Combinator tutorial]]
*[[Circuit network]]
*[[Circuit network]]
*[[Tutorial:Circuit-network_Cookbook|Circuit network cookbook]]
*[[Tutorial:Circuit network cookbook|Circuit network cookbook]]


{{LogisticsNav}}
{{LogisticsNav}}
{{C|Circuit network}}

Latest revision as of 18:18, 2 November 2024

Arithmetic combinator.png
Arithmetic combinator

ArithmeticSprite.png

Recipe

Time.png
0.5
+
Copper cable.png
5
+
Electronic circuit.png
5
Arithmetic combinator.png
1

Total raw

Time.png
8
+
Copper plate.png
10
+
Iron plate.png
5

Map color

Health

Quality normal.png 150
Quality uncommon.png 195 Quality rare.png 240
Quality epic.png 285 Quality legendary.png 375

Stack size

50

Rocket capacity

50 (1 stack)

Energy consumption

1 kw (electric)

Mining time

0.1

Prototype type

arithmetic-combinator

Internal name

arithmetic-combinator

Required technologies

Circuit network (research).png

Produced by

Assembling machine 1.png
Assembling machine 2.png
Assembling machine 3.png
Player.png

The arithmetic combinator is part of the circuit network and one of four types of combinators available in the game (along with the constant combinator, decider combinator, and selector combinator). Each arithmetic combinator can perform any one of the following mathematical operations on signals, and will show the corresponding symbol on its top:

Arith combinator anim.png

  • addition (+)
  • subtraction ()
  • multiplication (*)
  • division (/)
  • modulo (%)
  • exponentiation (^)
  • bit shift left (<<)
  • bit shift right (>>)
  • bitwise AND (&)
  • bitwise OR (|)
  • bitwise XOR (^)

The arithmetic combinator accepts two input connections (red and green wires), and sends its output to both output connections. The input wires connect to the nubs on the left side of the sprite in the sidebar, while the outputs connect to the right side.

GUI of the Arithmetic Combinator.

Function

The internal logic process has three steps:

  1. All input signals on the red and green wires are summed within the combinator.
  2. The specified operation is performed on the selected signal(s).
  3. The result of this operation is output as the selected output signal.

The operands can be any single signal or a constant value. Up to one of the operands can be the each virtual signal.

If neither operand is the each signal, the output must be a single signal. The operation is performed on the values of the chosen left and right signals, and the result is sent to the output on the specified signal.

If one operand is the each signal, then the output can be a single signal or the each signal. If the output is the each signal, then the operation is performed individually on the value of each input signal along with the value of the other operand, and each result is sent to the output on the same signal. If the output is a single signal, the operation is done on each of the input signals, the individual results are all added together, and that result is sent to the output on the specified signal.

Notes on operations

When using division, the result is truncated:

  • 21 / 10 = 2
  • 19 / 10 = 1
  • −21 / 10 = −2
  • −19 / 10 = −1
  • 21 / −10 = −2
  • 19 / −10 = −1
  • −21 / −10 = 2
  • −19 / −10 = 1

Modulo, indicated using % as it is in most programming languages, is the remainder after division. For example, 13 % 3 is 1 (13 = 4 * 3 + 1). This can, for example, be combined with truncated division as described above to separate out individual digits of a number for use in building visual indicators:

  • (24321 / 10000) % 10 = 2
  • (24321 / 1000) % 10 = 4
  • (24321 / 100) % 10 = 3
  • (24321 / 10) % 10 = 2
  • (24321 / 1) % 10 = 1

Negating the left operand of a modulo negates the result, while negating the right operand does nothing:

  • 13 % 3 = 1
  • 13 % −3 = 1
  • −13 % 3 = −1
  • −13 % −3 = −1

Bit shift right and Bit shift left deal with numbers in the binary representation. The 0's and 1's that make up a number are shifted in the specified direction which can result in a completely different number, due to the change in the binary value. The shift performed is called arithmetic shift, because it preserves the sign bit on bit shift right. If shifting left, a 0 is inserted into the least significant bit (LSB), and the bit in the most significant bit (MSB) is lost. If shifting right and the number is positive (MSB=0), a 0 is inserted into the MSB and the bit in the LSB is lost. If shifting right and the number is negative (MSB=1), a 1 is inserted into the MSB to keep the sign and the bit in the LSB is lost.

Example of a 'bit shift left'.
Example of a 'bit shift right (positive number)'.
Example of a 'bit shift right (negative number)'.

History

  • 2.0.7:
    • Received a UI overhaul.
      • Now displays input signals when configuring combinators.
      • Signals used by combinators can now be filtered between red, green, or both.
  • 0.15.0:
    • Added Modulo, Power, Left Bit Shift, Right Bit Shift, Bitwise AND, Bitwise OR and Bitwise XOR to the Arithmetic Combinator.
  • 0.13.0:
    • Connected wires are highlighted when hovering over a combinator connected to the circuit network.
    • Combinators show input and output in alt mode.
    • More virtual signals for combinators.
    • Constant combinator can be rotated.
    • Decider combinator "input count" option makes the combinator copy the count of the specified output signal from the input signals, instead of copying the count from the condition.
    • New combinator graphics.
  • 0.12.5:
    • Combinators now emit light.
  • 0.12.2:
    • Combinators no longer turn off when no wires are connected.

See Also