Skip to main content
Last updated

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.

ArgumentTypeDescription
numberdecimal or integerSpecifies 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
pact>(abs (- 10.5 23.7))13.2
pact
pact>(abs (- 10.5 23.7))13.2

The following example calculates the absolute value of an integer:

pact
pact>(abs (- 10 23))13
pact
pact>(abs (- 10 23))13

In 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.

ArgumentTypeDescription
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
pact>(+ 1 2)3
pact
pact>(+ 1 2)3
pact
pact>(+ 5.0 0.5)5.5
pact
pact>(+ 5.0 0.5)5.5
pact
pact>(+ "every" "body")"everybody"
pact
pact>(+ "every" "body")"everybody"
pact
pact>(+ [1 2] [3 4])[1 2 3 4]
pact
pact>(+ [1 2] [3 4])[1 2 3 4]
pact
pact>(+ { "foo": 100 } { "foo": 1, "bar": 2 }){"bar": 2,"foo": 100}
pact
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.

ArgumentTypeDescription
ax:<r> -> boolSpecifies the first function to apply value to.
bx:<r> -> boolSpecifies 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
pact>(and? (> 20) (> 10) 15)true
pact
pact>(and? (> 20) (> 10) 15)true

In 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.

ArgumentTypeDescription
xboolSpecifies the first boolean value for the AND operation.
yboolSpecifies 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
pact>(and true false)false
pact
pact>(and true false)false

In 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.

ArgumentTypeDescription
xintegerSpecifies the first operand.
yintegerSpecifies 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
pact>(& 2 3)2
pact
pact>(& 2 3)2
pact
pact>(& 5 -7)1
pact
pact>(& 5 -7)1

These 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.

ArgumentTypeDescription
XintegerSpecifies the first integer for the OR operation.
YintegerSpecifies 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
pact>(| 2 3)3
pact
pact>(| 2 3)3
pact
pact>(| 5 -7)-3
pact
pact>(| 5 -7)-3

These 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.

ArgumentTypeDescription
xintegerSpecifies 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
pact>(~ 15)-16
pact
pact>(~ 15)-16

This 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.

ArgumentTypeDescription
xdecimalSpecifies the decimal value to round up.
precinteger(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
pact>(ceiling 3.5)4
pact
pact>(ceiling 3.5)4

In 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
pact>(ceiling 100.15234 2)100.16
pact
pact>(ceiling 100.15234 2)100.16

In 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.

ArgumentTypeDescription
xintegerSpecifies 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
pact> (dec 3)3.0
pact
pact> (dec 3)3.0

In 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.

ArgumentTypeDescription
xinteger or decimalSpecifies the dividend.
yinteger or decimalSpecifies 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
pact>(/ 10.0 2.0)5.0
pact
pact>(/ 10.0 2.0)5.0
pact
pact>(/ 8 3)2
pact
pact>(/ 8 3)2

These 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.

ArgumentTypeDescription
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
pact>(= 5 5)true
pact
pact>(= 5 5)true
pact
pact>(= 3.14 2.71)false
pact
pact>(= 3.14 2.71)false
pact
pact>(= "hello" "hello")true
pact
pact>(= "hello" "hello")true
pact
pact>(= (time "2023-06-05T10:00:00Z") (time "2023-06-05T10:00:00Z"))true
pact
pact>(= (time "2023-06-05T10:00:00Z") (time "2023-06-05T10:00:00Z"))true
pact
pact>(= true false)false
pact
pact>(= true false)false
pact
pact>(= { "name": "Alice", "age": 30 } { "name": "Alice", "age": 30 })true
pact
pact>(= { "name": "Alice", "age": 30 } { "name": "Alice", "age": 30 })true
pact
pact>(= [1, 2, 3] [1, 2, 3])true
pact
pact>(= [1, 2, 3] [1, 2, 3])true

exp

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:

ArgumentTypeDescription
Xinteger or decimalSpecifies 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
pact>(round (exp 3) 6)20.085537
pact
pact>(round (exp 3) 6)20.085537

In 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:

ArgumentTypeDescription
XdecimalSpecifies the decimal value to round down.
PRECintegerSpecifies the precision for the rounding (optional).

Return values

The floor function returns the rounded-down value of the specified decimal:

  • If only X is provided, it returns an integer.
  • If PREC is provided, it returns a decimal with the specified precision.

Examples

The following examples demonstrate the floor function:

  1. Rounding down a decimal to an integer:
pact
pact>(floor 3.5)3
pact
pact>(floor 3.5)3
  1. Rounding down a decimal to a specified precision:
pact
pact>(floor 100.15234 2)100.15
pact
pact>(floor 100.15234 2)100.15

In 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.

ArgumentTypeDescription
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
pact>(>= 1 3)false
pact
pact>(>= 1 3)false
pact
pact>(>= 5.24 2.52)true
pact
pact>(>= 5.24 2.52)true
pact
pact>(>= "abc" "def")false
pact
pact>(>= "abc" "def")false

These 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.

ArgumentTypeDescription
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
pact>(> 1 3)false
pact
pact>(> 1 3)false
pact
pact>(> 5.24 2.52)true
pact
pact>(> 5.24 2.52)true
pact
pact>(> "abc" "def")false
pact
pact>(> "abc" "def")false

These 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.

ArgumentTypeDescription
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
pact>(<= 1 3)true
pact
pact>(<= 1 3)true
pact
pact>(<= 5.24 2.52)false
pact
pact>(<= 5.24 2.52)false
pact
pact>(<= "abc" "def")true
pact
pact>(<= "abc" "def")true

These 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.

ArgumentTypeDescription
Xinteger or decimalSpecifies 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
pact>(round (ln 60) 6)4.094345
pact
pact>(round (ln 60) 6)4.094345

In 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.

ArgumentTypeDescription
Xinteger or decimalSpecifies the base of the logarithm.
Yinteger or decimalSpecifies 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
pact>(log 2 256)8
pact
pact>(log 2 256)8

In 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.

ArgumentTypeDescription
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
pact>(< 1 3)true
pact
pact>(< 1 3)true
pact
pact>(< 5.24 2.52)false
pact
pact>(< 5.24 2.52)false
pact
pact>(< "abc" "def")true
pact
pact>(< "abc" "def")true

These 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.

ArgumentTypeDescription
XintegerSpecifies the dividend.
YintegerSpecifies 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
pact>(mod 13 8)5
pact
pact>(mod 13 8)5

In 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.

ArgumentTypeDescription
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
pact>(* 0.5 10.0)5.0
pact
pact>(* 0.5 10.0)5.0
pact
pact>(* 3 5)15
pact
pact>(* 3 5)15

These 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.

ArgumentTypeDescription
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
pact>(!= "hello" "goodbye")true
pact
pact>(!= "hello" "goodbye")true

This 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.

ArgumentTypeDescription
appx:<r> -> boolSpecifies 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
pact>(not? (> 20) 15)false
pact
pact>(not? (> 20) 15)false

In 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.

ArgumentTypeDescription
XboolSpecifies 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
pact>(not (> 1 2))true
pact
pact>(not (> 1 2))true

In 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.

ArgumentTypeDescription
ax:<r> -> boolSpecifies the first application function.
bx:<r> -> boolSpecifies 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
pact>(or? (> 20) (> 10) 15)true
pact
pact>(or? (> 20) (> 10) 15)true

In 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.

ArgumentTypeDescription
xboolSpecifies the first boolean value.
yboolSpecifies 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
pact>(or true false)true
pact
pact>(or true false)true

In 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.

ArgumentTypeDescription
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
pact>(^ 2 3)8
pact
pact>(^ 2 3)8

This 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.

ArgumentTypeDescription
XintegerSpecifies the integer value to be shifted.
YintegerSpecifies 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:

pact
(shift 255 8)65280
pact
(shift 255 8)65280

To shift the integer 255 1 bit to the right:

pact
(shift 255 -1)127
pact
(shift 255 -1)127

To shift the negative integer -255 8 bits to the left:

pact
(shift -255 8)-65280
pact
(shift -255 8)-65280

To shift the negative integer -255 1 bit to the right:

pact
(shift -255 -1)-128
pact
(shift -255 -1)-128

These 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.

ArgumentTypeDescription
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
pact>(sqrt 25)5
pact
pact>(sqrt 25)5

This 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.

ArgumentTypeDescription
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
pact>(- 1.0)-1.0
pact
pact>(- 1.0)-1.0
pact
pact>(- 3 2)1
pact
pact>(- 3 2)1

These 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.

ArgumentTypeDescription
XintegerSpecifies the first integer for the XOR operation.
YintegerSpecifies 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:

pact
(xor 127 64)63
pact
(xor 127 64)63
pact
(xor 5 -7)-4
pact
(xor 5 -7)-4

These examples illustrate how to use the xor function to perform bitwise XOR operations on integers in Pact, facilitating bitwise manipulation and logic operations.