Note
This function handles the unary minus operator, it negates the value of the given number.
function int.unm(x, self_changed) -- reverses the sign.| Parameter | Type | Description |
|---|---|---|
| x | int object only | Required. The value whose sign will be reversed. |
| self_changed | boolean (default: false) | Optional. Enable if you want to change the value in this object only. (disable copy object for optimization) |
Return Value:
Example:
local int = require("int") -- import module
local x, y = int.new("-12.2", "12.3456")
print(int.unm(x)) -- output: 12.2
print(int.unm(y)) -- output: -12.3456This feature lets you to call a function with an operator.
Important
function was embedded in __unm on metadata.
local int = require("int") -- import module
local x, y = int.new("-123", "12.3456")
print(-x) -- output: 123
print(-y) -- output: -12.3456This feature lets you to call functions on an object.
local int = require("int") -- import module
local x, y = int.new("-12.2", "12.3456")
print(x:unm()) -- output: 12.2
print(y:unm()) -- output: -12.3456Tip
In this example, a function inside the object is called and returns the object itself as the input.
also you can do like this:
local int = require("int") -- import module
local x, y = int.new("-12.2", "12.3456")
-- this works like "print(int.unm(x))"
print(y.unm(x)) -- output: 12.2
-- this works like "print(int.unm(y))"
print(x.unm(y)) -- output: -12.3456Tip
In this example, a function inside the object is called but a different object is used as the input.