Hamster-Scripts: Functions (built-in)

Integers

true

Gives a value representing a boolean value of TRUE.

Please note, that all values other than 0 represent TRUE, so "true" does in fact only give "an example" of a TRUE-value.

Returns: 1

$a = true

false

Gives the value representing a boolean value of FALSE.

Returns: 0

$a = false

isint( <expression> )

Solves the given expression and returns true if the result is an integer.

Returns: 1, if expression represents an integer-value, 0 otherwise

$result = iif( isint($a), $a, 0 )

int( <expression>, <error-default> )

int( <expression> )

Converts the given <expression> into an integer. If it is a string starting with "0x", the rest of the string is considered to be a hex-value.
If the given <expression> can't be converted to an integer value, the function returns the given <error-default> or 0 if none was given.

Returns: Integer-value; 0 or given <error-value> if string does not contain a valid integer.

$a = "1"
$b = 2
$c = $a + $b       # -> "12"
$d = int($a) + $b  # -> 3
print( int("0xFF") )  # -> 255
print( int("xyz","INVALID") )  # -> "INVALID"

abs( <number> )

Returns the absolute value of <number>.

Returns: Integer.

print( abs( 42) )  # -> 42
print( abs(-42) )  # -> 42

sgn( <number> )

Returns -1 if <number> if negative, +1 if it's positive and 0 if it's 0.

Returns: Integer.

print( sgn( 42) )  # -> 1
print( sgn(-42) )  # -> -1

[www.elbiah.de Hamster Playground Documentation]