Operators
abs
Use abs to calculate the absolute value of a given number.
Basic syntax
To calculate the absolute value of a number, use the following syntax:
(abs number)
Arguments
Use the following argument to specify the number for which you want to calculate the absolute value using the abs Pact function.
| Argument | Type | Description |
|---|---|---|
number | decimal or integer | Specifies the number for which to calculate the absolute value. |
Return values
The abs function returns the absolute value of the number as a decimal or integer, depending on the input type.
Examples
The following example calculates the absolute value of a decimal number in the Pact REPL:
pact>(abs (- 10.5 23.7))13.2pact>(abs (- 10.5 23.7))13.2The following example calculates the absolute value of an integer:
pact>(abs (- 10 23))13pact>(abs (- 10 23))13In these examples, abs returns the absolute value of the given numbers.
+
The + function performs addition for numbers, concatenation for strings/lists, or merging for objects.
Basic syntax
To perform addition for numbers, use the following syntax:
(+ x y)
To concatenate strings/lists or merge objects, use the following syntax:
(+ x y)
Arguments
Use the following arguments to specify the values for addition, concatenation, or merging using the + Pact function.
| Argument | Type | Description |
|---|---|---|
x | <a[integer,decimal,string,[<l>],object:<{o}>]> | Specifies the first operand. |
y | <a[integer,decimal,string,[<l>],object:<{o}>]> | Specifies the second operand. |
Return value
The + function returns the result of addition for numbers, concatenation for strings/lists, or merging for objects.
Examples
The following examples demonstrate the usage of the + function within a Pact REPL. They perform addition, concatenation, or merging:
pact>(+ 1 2)3pact>(+ 1 2)3pact>(+ 5.0 0.5)5.5pact>(+ 5.0 0.5)5.5pact>(+ "every" "body")"everybody"pact>(+ "every" "body")"everybody"pact>(+ [1 2] [3 4])[1 2 3 4]pact>(+ [1 2] [3 4])[1 2 3 4]pact>(+ { "foo": 100 } { "foo": 1, "bar": 2 }){"bar": 2,"foo": 100}pact>(+ { "foo": 100 } { "foo": 1, "bar": 2 }){"bar": 2,"foo": 100}These examples illustrate how to use the + function to perform addition for numbers, concatenation for strings/lists, or merging for objects in Pact, facilitating various types of operations.
and?
Use and? to apply a logical AND operation to the results of applying a value to a and b, with short-circuiting.
Basic syntax
To apply logical 'and' to the results of applying value to a and b, use the following syntax:
(and? a b value)
Arguments
Use the following arguments to specify the functions and value for the and? operation.
| Argument | Type | Description |
|---|---|---|
a | x:<r> -> bool | Specifies the first function to apply value to. |
b | x:<r> -> bool | Specifies the second function to apply value to. |
value | <r> | Specifies the value to apply to both a and b functions. |
Return values
The and? function returns a boolean value based on the result of applying value to a and b with the logical AND operation.
Examples
The following example demonstrates the and? operation in the Pact REPL:
pact>(and? (> 20) (> 10) 15)truepact>(and? (> 20) (> 10) 15)trueIn this example, the and? function applies the functions > 20 and > 10 to the value 15, resulting in false because the second conditions 10 > 15 is false.
and
Use and to perform a boolean logic AND operation with short-circuiting.
Basic syntax
To perform a boolean logic AND operation between two boolean values x and y, use the following syntax:
(and x y)
Arguments
Use the following arguments to specify the boolean values for the and operation.
| Argument | Type | Description |
|---|---|---|
x | bool | Specifies the first boolean value for the AND operation. |
y | bool | Specifies the second boolean value for the AND operation. |
Return values
The and function returns a boolean value based on the result of the AND operation between the input boolean values.
Examples
The following example demonstrates the and operation in the Pact REPL:
pact>(and true false)falsepact>(and true false)falseIn this example, the and function performs a boolean AND operation between the values true and false, resulting in false.
&
The & function computes the bitwise AND operation between the first argument x and the second argument y.
Basic syntax
To compute the bitwise AND operation between x and y, use the following syntax:
(& x y)
Arguments
Use the following arguments to specify the values for bitwise AND operation using the & Pact function.
| Argument | Type | Description |
|---|---|---|
x | integer | Specifies the first operand. |
y | integer | Specifies the second operand. |
Return value
The & function returns the result of the bitwise AND operation between x and y.
Examples
The following examples demonstrate the usage of the & function within a Pact REPL. They perform bitwise AND operations:
pact>(& 2 3)2pact>(& 2 3)2pact>(& 5 -7)1pact>(& 5 -7)1These examples illustrate how to use the & function to compute bitwise AND operations in Pact, facilitating bitwise manipulation of integer values.
|
The | function computes the bitwise OR operation between two integers.
Basic syntax
To compute the bitwise OR operation between two integers X and Y, use the following syntax:
(| X Y)
Arguments
Use the following arguments to specify the integers for the bitwise OR operation using the | Pact function.
| Argument | Type | Description |
|---|---|---|
X | integer | Specifies the first integer for the OR operation. |
Y | integer | Specifies the second integer for the OR operation. |
Return value
The | function returns the result of the bitwise OR operation as an integer.
Examples
The following examples demonstrate the usage of the | function within a Pact script. They compute the bitwise OR operation between two integers:
pact>(| 2 3)3pact>(| 2 3)3pact>(| 5 -7)-3pact>(| 5 -7)-3These examples illustrate how to use the | function to perform bitwise OR operations on integers in Pact, facilitating bitwise manipulation and logic operations.
~
The ~ function reverses all bits in the provided integer.
Basic syntax
To reverse all bits in an integer x, use the following syntax:
(~ x)
Arguments
Use the following argument to specify the integer for bit reversal using the ~ Pact function.
| Argument | Type | Description |
|---|---|---|
x | integer | Specifies the integer for which to reverse all bits. |
Return value
The ~ function returns the result of reversing all bits in the provided integer.
Examples
The following example demonstrates the usage of the ~ function within a Pact script. It reverses all bits in the integer 15:
pact>(~ 15)-16pact>(~ 15)-16This example illustrates how to use the ~ function to reverse all bits in an integer in Pact, facilitating bitwise manipulation.
ceiling
Use ceiling to round up the value of a decimal x to the nearest integer or to a specified precision prec as a decimal.
Basic syntax
To round up the value of a decimal x to the nearest integer, use the following syntax:
(ceiling x)
To round up the value of a decimal x to a specified precision prec as a decimal, use the following syntax:
(ceiling x prec)
Arguments
Use the following arguments to specify the decimal x and optional precision prec for the ceiling Pact function.
| Argument | Type | Description |
|---|---|---|
x | decimal | Specifies the decimal value to round up. |
prec | integer | (Optional) Specifies the precision to which to round the x value. If not provided, x is rounded up to the nearest integer. |
Return values
The ceiling function returns the rounded-up value of x as either an integer or a decimal based on the input and precision.
Examples
The following example rounds up a decimal value to the nearest integer in the Pact REPL:
pact>(ceiling 3.5)4pact>(ceiling 3.5)4In this example, ceiling rounds up the decimal value 3.5 to the nearest integer, resulting in 4.
The following example rounds up a decimal value to a precision of 2 decimal places:
pact>(ceiling 100.15234 2)100.16pact>(ceiling 100.15234 2)100.16In this example, ceiling rounds up the decimal value 100.15234 to a precision of 2 decimal places, resulting in 100.16.
dec
Use dec to cast an integer x to a decimal value.
Basic syntax
To cast an integer x to a decimal value, use the following syntax:
(dec X)
Arguments
Use the following argument to specify the integer x for the dec Pact function.
| Argument | Type | Description |
|---|---|---|
x | integer | Specifies the integer to cast to a decimal value. |
Return values
The dec function returns the specified integer x as a decimal value.
Example
The following example demonstrates the dec function:
pact> (dec 3)3.0pact> (dec 3)3.0In this example, (dec 3) is used to cast the integer 3 to a decimal value. The function returns 3.0 as a decimal. This can be useful when you need to work with decimal values in Pact but have integer inputs.
/
The / function divides the first argument x by the second argument y.
Basic syntax
To divide x by y, use the following syntax:
(/ x y)
Arguments
Use the following arguments to specify the values for division using the / Pact function.
| Argument | Type | Description |
|---|---|---|
x | integer or decimal | Specifies the dividend. |
y | integer or decimal | Specifies the divisor. |
Return value
The / function returns the result of dividing x by y.
Examples
The following examples demonstrate the usage of the / function within a Pact REPL. They divide two values:
pact>(/ 10.0 2.0)5.0pact>(/ 10.0 2.0)5.0pact>(/ 8 3)2pact>(/ 8 3)2These examples illustrate how to use the / function to perform division operations in Pact, facilitating arithmetic calculations with both integer and decimal values.
=
The = function returns true if the first argument x is equal to the second argument y.
Basic syntax
To check if x is equal to y, use the following syntax:
(= x y)
Arguments
Use the following arguments to specify the values for comparison using the = Pact function.
| Argument | Type | Description |
|---|---|---|
x | <a[integer,decimal,string,time,bool,object,list,table]> | Specifies the first value for comparison. |
y | <a[integer,decimal,string,time,bool,object,list,table]> | Specifies the second value for comparison. |
Return value
The = function returns a boolean value indicating whether x is equal to y.
Examples
The following examples demonstrate the usage of the = function within a Pact REPL. They compare two values to check if the first value is equal to the second value:
pact>(= 5 5)truepact>(= 5 5)truepact>(= 3.14 2.71)falsepact>(= 3.14 2.71)falsepact>(= "hello" "hello")truepact>(= "hello" "hello")truepact>(= (time "2023-06-05T10:00:00Z") (time "2023-06-05T10:00:00Z"))truepact>(= (time "2023-06-05T10:00:00Z") (time "2023-06-05T10:00:00Z"))truepact>(= true false)falsepact>(= true false)falsepact>(= { "name": "Alice", "age": 30 } { "name": "Alice", "age": 30 })truepact>(= { "name": "Alice", "age": 30 } { "name": "Alice", "age": 30 })truepact>(= [1, 2, 3] [1, 2, 3])truepact>(= [1, 2, 3] [1, 2, 3])trueexp
Use exp to calculate the exponential function of the specified X.
Basic syntax
To calculate the exponential function of a value, use the following syntax:
(exp X)
Arguments
Use the following argument to specify the value for the exp Pact function:
| Argument | Type | Description |
|---|---|---|
X | integer or decimal | Specifies the value for which to calculate the exponential function. |
Return values
The exp function returns the exponential function of the specified value.
Examples
The following example demonstrates the exp function:
pact>(round (exp 3) 6)20.085537pact>(round (exp 3) 6)20.085537In this example, (exp 3) is used to calculate the exponential function of 3. The result of this calculation is then rounded to 6 decimal places. The exp function provides a way to calculate exponential values in Pact contracts.
floor
Use floor to round down the value of a decimal X to an integer, or to a specified precision PREC as a decimal.
Basic syntax
To round down a decimal value to an integer or to a specified precision, use the following syntax:
(floor X)
or
(floor X PREC)
Arguments
Use the following arguments to specify the decimal value and precision for the floor Pact function:
| Argument | Type | Description |
|---|---|---|
X | decimal | Specifies the decimal value to round down. |
PREC | integer | Specifies the precision for the rounding (optional). |
Return values
The floor function returns the rounded-down value of the specified decimal:
- If only
Xis provided, it returns an integer. - If
PRECis provided, it returns a decimal with the specified precision.
Examples
The following examples demonstrate the floor function:
- Rounding down a decimal to an integer:
pact>(floor 3.5)3pact>(floor 3.5)3- Rounding down a decimal to a specified precision:
pact>(floor 100.15234 2)100.15pact>(floor 100.15234 2)100.15In these examples, (floor 3.5) rounds down the decimal 3.5 to 3, and (floor 100.15234 2) rounds down the decimal 100.15234 to 100.15. The floor function is useful for situations where you need to round down decimal values in Pact contracts.
>=
The >= function returns true if the first argument x is greater than or equal to the second argument y.
Basic syntax
To check if x is greater than or equal to y, use the following syntax:
(>= x y)
Arguments
Use the following arguments to specify the values for comparison using the >= Pact function.
| Argument | Type | Description |
|---|---|---|
x | <a[integer,decimal,string,time]> | Specifies the first value for comparison. |
y | <a[integer,decimal,string,time]> | Specifies the second value for comparison. |
Return value
The >= function returns a boolean value indicating whether x is greater than or equal to y.
Examples
The following examples demonstrate the usage of the >= function within a Pact REPL. They compare two values to check if the first value is greater than or equal to the second value:
pact>(>= 1 3)falsepact>(>= 1 3)falsepact>(>= 5.24 2.52)truepact>(>= 5.24 2.52)truepact>(>= "abc" "def")falsepact>(>= "abc" "def")falseThese examples illustrate how to use the >= function to perform comparison operations in Pact, facilitating logical comparisons between different types of values.
>
The > function returns true if the first argument x is greater than the second argument y.
Basic syntax
To check if x is greater than y, use the following syntax:
(> x y)
Arguments
Use the following arguments to specify the values for comparison using the > Pact function.
| Argument | Type | Description |
|---|---|---|
x | <a[integer,decimal,string,time]> | Specifies the first value for comparison. |
y | <a[integer,decimal,string,time]> | Specifies the second value for comparison. |
Return value
The > function returns a boolean value indicating whether x is greater than y.
Examples
The following examples demonstrate the usage of the > function within a Pact script. They compare two values to check if the first value is greater than the second value:
pact>(> 1 3)falsepact>(> 1 3)falsepact>(> 5.24 2.52)truepact>(> 5.24 2.52)truepact>(> "abc" "def")falsepact>(> "abc" "def")falseThese examples illustrate how to use the > function to perform comparison operations in Pact, facilitating logical comparisons between different types of values.
<=
The <= function returns true if the first argument x is less than or equal to the second argument y.
Basic syntax
To check if x is less than or equal to y, use the following syntax:
(<= x y)
Arguments
Use the following arguments to specify the values for comparison using the <= Pact function.
| Argument | Type | Description |
|---|---|---|
x | <a[integer,decimal,string,time]> | Specifies the first value for comparison. |
y | <a[integer,decimal,string,time]> | Specifies the second value for comparison. |
Return value
The <= function returns a boolean value indicating whether x is less than or equal to y.
Examples
The following examples demonstrate the usage of the <= function within a Pact script. They compare two values to check if the first value is less than or equal to the second value:
pact>(<= 1 3)truepact>(<= 1 3)truepact>(<= 5.24 2.52)falsepact>(<= 5.24 2.52)falsepact>(<= "abc" "def")truepact>(<= "abc" "def")trueThese examples illustrate how to use the <= function to perform comparison operations in Pact, facilitating logical comparisons between different types of values.
ln
Use ln to compute the natural logarithm of X.
Basic syntax
To compute the natural logarithm of a value, use the following syntax:
(ln X)
Argument
Use the following argument to specify the value for which you want to compute the natural logarithm using the ln Pact function.
| Argument | Type | Description |
|---|---|---|
X | integer or decimal | Specifies the value for which you want to compute the natural logarithm. |
Return value
The ln function returns the natural logarithm of the specified value.
Examples
The following example demonstrates the use of ln in the Pact REPL:
pact>(round (ln 60) 6)4.094345pact>(round (ln 60) 6)4.094345In this example, the natural logarithm of 60 is computed and rounded to 6 decimal places, resulting in approximately 4.094345.
log
Use log to compute the logarithm of Y with base X.
Basic syntax
To compute the logarithm of Y with base X, use the following syntax:
(log X Y)
Arguments
Use the following arguments to specify the base (X) and value (Y) for which you want to compute the logarithm using the log Pact function.
| Argument | Type | Description |
|---|---|---|
X | integer or decimal | Specifies the base of the logarithm. |
Y | integer or decimal | Specifies the value for which you want to compute the logarithm. |
Return value
The log function returns the logarithm of Y with base X.
Examples
The following example demonstrates the use of log in the Pact REPL:
pact>(log 2 256)8pact>(log 2 256)8In this example, the logarithm of 256 with base 2 is computed, resulting in 8.
<
The < function returns true if the first argument x is less than the second argument y.
Basic syntax
To check if x is less than y, use the following syntax:
(< x y)
Arguments
Use the following arguments to specify the values for comparison using the < Pact function.
| Argument | Type | Description |
|---|---|---|
x | <a[integer,decimal,string,time]> | Specifies the first value for comparison. |
y | <a[integer,decimal,string,time]> | Specifies the second value for comparison. |
Return value
The < function returns a boolean value indicating whether x is less than y.
Examples
The following examples demonstrate the usage of the < function within a Pact script. They compare two values to check if the first value is less than the second value:
pact>(< 1 3)truepact>(< 1 3)truepact>(< 5.24 2.52)falsepact>(< 5.24 2.52)falsepact>(< "abc" "def")truepact>(< "abc" "def")trueThese examples illustrate how to use the < function to perform comparison operations in Pact, facilitating logical comparisons between different types of values.
mod
Use mod to compute the remainder of X divided by Y.
Basic syntax
To compute the remainder of X divided by Y, use the following syntax:
(mod X Y)
Arguments
Use the following arguments to specify the integers for which you want to compute the remainder using the mod Pact function.
| Argument | Type | Description |
|---|---|---|
X | integer | Specifies the dividend. |
Y | integer | Specifies the divisor. |
Return value
The mod function returns the remainder of the division of X by Y.
Examples
The following example demonstrates the use of mod in the Pact REPL:
pact>(mod 13 8)5pact>(mod 13 8)5In this example, the remainder of 13 divided by 8 is computed, resulting in 5.
*
The * function multiplies the first argument x by the second argument y.
Basic syntax
To multiply x by y, use the following syntax:
(* x y)
Arguments
Use the following arguments to specify the values for multiplication using the * Pact function.
| Argument | Type | Description |
|---|---|---|
x | <a[integer,decimal]> | Specifies the first multiplier. |
y | <a[integer,decimal]> | Specifies the second multiplier. |
Return value
The * function returns the result of multiplying x by y.
Examples
The following examples demonstrate the usage of the * function within a Pact script. They perform multiplication:
pact>(* 0.5 10.0)5.0pact>(* 0.5 10.0)5.0pact>(* 3 5)15pact>(* 3 5)15These examples illustrate how to use the * function to perform multiplication operations in Pact, facilitating arithmetic calculations with both integer and decimal values.
!=
The != function returns true if the first argument x does not equal the second argument y.
Basic syntax
To check if x does not equal y, use the following syntax:
(!= x y)
Arguments
Use the following arguments to specify the values for comparison using the != Pact function.
| Argument | Type | Description |
|---|---|---|
x | <a[integer, string, time, decimal, bool, [<l>], object:<{o}>, keyset, guard, module{}]> | Specifies the first value for comparison. |
y | <a[integer, string, time, decimal, bool, [<l>], object:<{o}>, keyset, guard, module{}]> | Specifies the second value for comparison. |
Return value
The != function returns true if x does not equal y, otherwise false.
Examples
The following example demonstrates the usage of the != function within the Pact REPL. It checks if two strings are not equal:
pact>(!= "hello" "goodbye")truepact>(!= "hello" "goodbye")trueThis example illustrates how to use the != function to compare values for inequality in Pact, allowing for conditional logic based on whether two values are not equal.
not?
Use not? to apply logical 'not' to the results of applying a value to an application function.
Basic syntax
To apply logical 'not' to the results of applying a value to an application function app, use the following syntax:
(not? app value)
Arguments
Use the following arguments to specify the application function and the value to be applied using the not? Pact function.
| Argument | Type | Description |
|---|---|---|
app | x:<r> -> bool | Specifies the application function. |
value | <r> | Specifies the value to be applied to the application function. |
Return value
The not? function returns a boolean value representing the logical negation of the result of applying the value to the application function.
Examples
The following example demonstrates the use of not? in the Pact REPL:
pact>(not? (> 20) 15)falsepact>(not? (> 20) 15)falseIn this example, the application function is >(20) and the value is 15. The expression >(20, 15) evaluates to true, and not? negates this value, resulting in false.
not
Use not to compute the boolean negation of a value.
Basic syntax
To compute the boolean negation of X, use the following syntax:
(not X)
Argument
Use the following argument to specify the boolean value for which you want to compute the negation using the not Pact function.
| Argument | Type | Description |
|---|---|---|
X | bool | Specifies the boolean value to be negated. |
Return value
The not function returns the boolean negation of the input value.
Examples
The following example demonstrates the use of not in the Pact REPL:
pact>(not (> 1 2))truepact>(not (> 1 2))trueIn this example, the expression >(1, 2) evaluates to false, and not negates this value, resulting in true.
or?
Use or? to apply logical 'or' with short-circuit evaluation to the results of applying a value to two application functions.
Basic syntax
To apply logical 'or' with short-circuit evaluation to the results of applying a value to two application functions, use the following syntax:
(or? a b value)
Arguments
Use the following arguments to specify the application functions and the value to be applied using the or? Pact function.
| Argument | Type | Description |
|---|---|---|
a | x:<r> -> bool | Specifies the first application function. |
b | x:<r> -> bool | Specifies the second application function. |
value | <r> | Specifies the value to be applied to both application functions. |
Return value
The or? function returns a boolean value representing the logical 'or' operation with short-circuit evaluation applied to the results of applying the value to the two application functions.
Examples
The following example demonstrates the use of or? in the Pact REPL:
pact>(or? (> 20) (> 10) 15)truepact>(or? (> 20) (> 10) 15)trueIn this example, the value 15 is applied to the application functions >(20) and >(10). The logical 'or' operation with short-circuit evaluation is performed on the results, resulting in true.
or
Use or for boolean logic with short-circuit evaluation.
Basic syntax
To perform boolean logic with short-circuit evaluation, use the following syntax:
(or x y)
Arguments
Use the following arguments to specify the boolean values for which you want to perform the logical OR operation using the or Pact function.
| Argument | Type | Description |
|---|---|---|
x | bool | Specifies the first boolean value. |
y | bool | Specifies the second boolean value. |
Return value
The or function returns a boolean value based on the logical OR operation of the input values.
Examples
The following example demonstrates the use of or in the Pact REPL:
pact>(or true false)truepact>(or true false)trueIn this example, the logical OR operation is performed between true and false, resulting in true.
^
The ^ function raises the first argument x to the power of the second argument y.
Basic syntax
To raise x to the power of y, use the following syntax:
(^ x y)
Arguments
Use the following arguments to specify the base and exponent for raising to a power using the ^ Pact function.
| Argument | Type | Description |
|---|---|---|
x | <a[integer,decimal]> | Specifies the base value. |
y | <a[integer,decimal]> | Specifies the exponent value. |
Return value
The ^ function returns the result of raising x to the power of y.
Examples
The following example demonstrates the usage of the ^ function within a Pact REPL. It raises 2 to the power of 3:
pact>(^ 2 3)8pact>(^ 2 3)8This example illustrates how to use the ^ function to perform exponentiation in Pact, enabling mathematical operations involving powers.
shift
The shift function performs a bitwise shift operation on the integer X by Y bits. If Y is positive, it shifts X to the left; otherwise, it shifts X to the right. Right shifts perform sign extension on signed number types, filling the top bits with 1 if X is negative and with 0 otherwise.
Basic syntax
To shift the integer X by Y bits, use the following syntax:
(shift X Y)
Arguments
Use the following arguments to specify the integer values to be shifted using the shift Pact function.
| Argument | Type | Description |
|---|---|---|
X | integer | Specifies the integer value to be shifted. |
Y | integer | Specifies the number of bits to shift X by. |
Return value
The shift function returns the result of shifting X by Y bits.
Examples
The following examples demonstrate the usage of the shift function within a Pact script.
To shift the integer 255 8 bits to the left:
(shift 255 8)65280(shift 255 8)65280To shift the integer 255 1 bit to the right:
(shift 255 -1)127(shift 255 -1)127To shift the negative integer -255 8 bits to the left:
(shift -255 8)-65280(shift -255 8)-65280To shift the negative integer -255 1 bit to the right:
(shift -255 -1)-128(shift -255 -1)-128These examples illustrate how to use the shift function to perform bitwise shift operations on integers in Pact, either to the left or to the right, with sign extension for right shifts on signed numbers.
sqrt
The sqrt function computes the square root of the given value X.
Basic syntax
To calculate the square root of a value, use the following syntax:
(sqrt X)
Arguments
Use the following argument to specify the value for which to compute the square root using the sqrt Pact function.
| Argument | Type | Description |
|---|---|---|
X | <a[integer,decimal]> | Specifies the value for which to compute the square root. |
Return value
The sqrt function returns the square root of the specified value. The return type matches the type of the input value, either an integer or a decimal.
Examples
The following example demonstrates the usage of the sqrt function within the Pact REPL. It calculates the square root of the value 25:
pact>(sqrt 25)5pact>(sqrt 25)5This example illustrates how to use the sqrt function to compute the square root of a value in Pact, producing either an integer or a decimal result.
-
The - function negates the argument x, or subtracts y from x.
Basic syntax
To negate x, use the following syntax:
(- x)
To subtract y from x, use the following syntax:
(- x y)
Arguments
Use the following arguments to specify the values for negation or subtraction using the - Pact function.
| Argument | Type | Description |
|---|---|---|
x | <a[integer,decimal]> | Specifies the value to be negated or subtracted from. |
y | <a[integer,decimal]> | Specifies the value to subtract from x. |
Return value
The - function returns the negation of x, or the result of subtracting y from x.
Examples
The following examples demonstrate the usage of the - function within a Pact REPL. They negate values or perform subtraction:
pact>(- 1.0)-1.0pact>(- 1.0)-1.0pact>(- 3 2)1pact>(- 3 2)1These examples illustrate how to use the - function to negate values or perform subtraction operations in Pact, facilitating arithmetic calculations with both integer and decimal values.
xor
The xor function computes the bitwise XOR (exclusive OR) operation between two integers.
Basic syntax
To compute the bitwise XOR operation between two integers, use the following syntax:
(xor X Y)
Arguments
Use the following arguments to specify the integers for the bitwise XOR operation using the xor Pact function.
| Argument | Type | Description |
|---|---|---|
X | integer | Specifies the first integer for the XOR operation. |
Y | integer | Specifies the second integer for the XOR operation. |
Return value
The xor function returns the result of the bitwise XOR operation as an integer.
Examples
The following examples demonstrate the usage of the xor function within the Pact REPL. They compute the bitwise XOR operation between two integers:
(xor 127 64)63(xor 127 64)63(xor 5 -7)-4(xor 5 -7)-4These examples illustrate how to use the xor function to perform bitwise XOR operations on integers in Pact, facilitating bitwise manipulation and logic operations.