____ ____ ____ ____ 
||n |||i |||m |||f ||
||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|

	

the nimf guide : api : " num "

The nimf num module provides helpers for dealing with numbers. By convention words within this module will begin with the prefix `num.`.

Words


num.abs

Signature: ( n -- +n )

Description: Eats a number from TOS and leaves its absolute value on the stack.

num.negate

Signature: ( n -- -n )

Description: Eats a number from TOS and leaves a negative version of the number on the stack. If the number is already negative it will be returned to TOS unchanged.

num.min

Signature: ( n1 n2 -- min )

Description: Eats two numbers from TOS and leaves the lower of the two on the stack.

num.max

Signature: ( n1 n2 -- max )

Description: Eats two numbers from TOS and leaves the higher of the two on the stack.

num.between

Signature: ( value n1 n2 -- flag )

Description: Eats two numbers that act as a range and a value to check from TOS. Leaves a flag, that indicates if the value falls between the start and end of the range (non-inclusive), on the stack. The range can be passed in any order (they will be swapped if necessary by the word).

num.within

Signature: ( value n1 n2 -- flag )

Description: Eats two numbers that act as a range and a value to check from TOS. Leaves a flag, that indicates if the value falls between the start and end of the range (inclusive), on the stack. The range can be passed in any order (they will be swapped if necessary by the word).

num.digit-length

Signature: ( n -- n )

Description: Eats a number from TOS and leaves the number of digits it contains. For example, 100 has 3 digits.

Note: For purposes of this word if a number is negative, the minus sign counts as a digit. -123 would be 4 digits. This is in place in order to provide display padding for numbers. If you would like to avoid this, it would be trivial to make a word that detects a negative number, gets the digit length, and subtracts one from it.

num.print-left-pad

Signature: ( n width -- )

Description: Eats a number representing a width, in printable characters, and a number value from TOS. Leaves nothing on the stack. Prints the number with padding to the left in order to make the number + spaces take up the width value. If a number is already larger than the width it will be printed without any added spacing.

num.print-right-pad

Signature: ( n width -- )

Description: Eats a number representing a width, in printable characters, and a number value from TOS. Leaves nothing on the stack. Prints the number with padding to the right in order to make the number + spaces take up the width value. If a number is already larger than the width it will be printed without any added spacing.

num.zero?

Signature: ( n -- flag )

Description: Eats a number from TOS and leaves a flag indicating if the number is equal to zero.

num.negative?

Signature: ( n -- flag )

Description: Eats a number from TOS and leaves a flag indicating if the number is less than zero.

num.positive?

Signature: ( n -- flag )

Description: Eats a number from TOS and leaves a flag indicating if the number is greater than zero.