Integer
Math Negate Integer
The Math Negate Integer node performs a negation operation on an input integer value. It multiplies the input by -1, effectively changing its sign from positive to negative or vice versa.
Inputs
a
(integer, default: 0): The input integer value to be negated.
Outputs
result
(integer): The negated value of the input integer.
Configuration
This node does not have any configuration options.
Usage
To use the Math Negate Integer node:
- Connect an integer value to the
a
input port. This is the value that will be negated. - The negated value will be available at the
result
output port, which can be connected to other nodes in your spell.
Example
Let’s say you have a spell that calculates the difference between two values, but you want to ensure the result is always positive. You can use the Math Negate Integer node to negate the difference if it’s negative.
Here’s how the spell might look:
- Connect the first value to a Math Subtract node’s
a
input. - Connect the second value to the Math Subtract node’s
b
input. - Connect the Math Subtract node’s
result
output to a Math Negate Integer node’sa
input. - Connect a Math Greater Than node’s
a
input to the Math Subtract node’sresult
output. - Connect a constant value of 0 to the Math Greater Than node’s
b
input. - Connect the Math Greater Than node’s
result
output to a Math If node’scondition
input. - Connect the Math Negate Integer node’s
result
output to the Math If node’sthen
input. - Connect the Math Subtract node’s
result
output to the Math If node’selse
input.
Now, if the difference between the two input values is negative, the Math Negate Integer node will make it positive. The Math If node will return the negated value if the difference is less than 0, otherwise it will return the original difference.
Best Practices
- Be mindful of the input value’s sign. Negating a negative value will make it positive.
- Remember that the Math Negate Integer node only works with integers. For floating-point numbers, use the Math Negate Float node instead.
Common Issues
- Forgetting to handle negative differences: If you subtract a larger number from a smaller one, the result will be negative. Use the Math Negate Integer node in combination with a Math If node to handle this case if needed.
- Incorrect data type: Ensure that the input to the Math Negate Integer node is actually an integer. Connecting a different data type will cause unexpected behavior.