-- Value -- Value

Value

The value to convert.

Returns

Number Number

0 If the given operand is FALSE, 1 if it is TRUE and the unchanged operand if it is a number.

Returns 0 if the given operand is FALSE, 1 if it is TRUE and the operand unchanged if is a number. -- FALSE -- FALSE returns 0 and -- TRUE -- TRUE returns 1.

This operator is typically used to convert an array of logical values to an array of numbers. This formula returns the array { 1, 0, 0 }{ 1; 0; 0 }:

-- { TRUE, FALSE, FALSE }
-- { TRUE; FALSE; FALSE }

This is useful in a variety of situations — refer to the examples below.

The TONUMBER function is similar, but can also convert text strings.

Examples

-- FALSE
-- FALSE

Returns 0.

-- { FALSE, TRUE }
-- { FALSE; TRUE }

Returns the array { 0, 1 }{ 0; 1 }.

SUM ( -- ({ 1, 2, 3, 4, 5 } > 3))
SUM ( -- ({ 1; 2; 3; 4; 5 } > 3))

Returns the number of array members which are greater than 3. (In this case, only 4 and 5 are greater than 3, meaning that 2 is returned.) When applied to { 1, 2, 3, 4, 5 }{ 1; 2; 3; 4; 5 } and 33, > returns a logical array with the same number of elements as the { 1, 2, 3, 4, 5 }{ 1; 2; 3; 4; 5 } number array, where individual logical values indicate if the corresponding number in the number array is greater than 3. In other words, { 1, 2, 3, 4, 5 } > 3{ 1; 2; 3; 4; 5 } > 3 returns { FALSE, FALSE, FALSE, TRUE, TRUE }{ FALSE; FALSE; FALSE; TRUE; TRUE }, which the -- operator turns into { 0, 0, 0, 1, 1 }{ 0; 0; 0; 1; 1 }. Finally, the SUM functions adds together all elements, yielding 2.

SUM ( -- ( ISODD ({ 1, 2, 3, 4, 5 })))
SUM ( -- ( ISODD ({ 1; 2; 3; 4; 5 })))

Returns the number of array elements which are odd. The ISODD function returns the logical array { TRUE, FALSE, TRUE, FALSE, TRUE }{ TRUE; FALSE; TRUE; FALSE; TRUE }, indicating that 11, 33 and 55 are odd, whereas 22 and 44 are even. The -- operator then turns that logical array into the number array { 1, 0, 1, 0, 1 }{ 1; 0; 1; 0; 1 }. When given that array, the SUM function returns 3, indicating that three of the array elements are odd.

SUM ( -- ( ISODD ({ 1, 2, 3 }) || ({ 1, 2, 3 } > 1)))
SUM ( -- ( ISODD ({ 1; 2; 3 }) || ({ 1; 2; 3 } > 1)))

Returns the number of array elements which are odd or are greater than 1. All array elements qualify, meaning that 3 is returned. ISODD ({ 1, 2, 3 }) ISODD ({ 1; 2; 3 }) returns the logical array { TRUE, FALSE, TRUE }{ TRUE; FALSE; TRUE }, because only 1 and 3 are odd numbers. { 1, 2, 3 } > 1{ 1; 2; 3 } > 1 returns the logical array { FALSE, TRUE, TRUE }{ FALSE; TRUE; TRUE }, as the array elements 2 and 3 are greater than 1. The || operator ("logical or") returns the logical array { TRUE, TRUE, TRUE }{ TRUE; TRUE; TRUE }, because every element of the array { 1, 2, 3 }{ 1; 2; 3 } is either odd, or is greater than 1. When given that array, after the -- operator has turned it into a number array, the SUM function returns 3, indicating that three of the array elements are either odd or are greater than 1.

SUM ( -- ( ISODD ({ 1, 2, 3 }) && ({ 1, 2, 3 } > 1)))
SUM ( -- ( ISODD ({ 1; 2; 3 }) && ({ 1; 2; 3 } > 1)))

Returns the number of array elements which are both odd and are greater than 1. Only the array element 3 qualifies, meaning that 1 is returned. ISODD ({ 1, 2, 3 }) ISODD ({ 1; 2; 3 }) returns the logical array { TRUE, FALSE, TRUE }{ TRUE; FALSE; TRUE }, because only 1 and 3 are odd numbers. { 1, 2, 3 } > 1{ 1; 2; 3 } > 1 returns the logical array { FALSE, TRUE, TRUE }{ FALSE; TRUE; TRUE }, as the array elements 2 and 3 are greater than 1. The && operator ("logical and") returns the logical array { FALSE, FALSE, TRUE }{ FALSE; FALSE; TRUE }, which is FALSE for the first element 1 (as it isn't greater than 1), is FALSE for the second element 2 (as it isn't odd) and is TRUE for the third element 3 (as it is both greater than 1 and is odd). When given that array, after the -- operator has turned it into a number array, the SUM function returns 1, indicating that one element of the original array is both odd and is greater than 1.

fxEngine Shell Want this in your own terminal? A standalone version is coming. Get notified.
Loading fxEngine Shell