kex docs Standard Library

Number

type Integer

Implements Monoid, Group, Blankable, Truthyable.

even?

even? : Bool

Returns true if the integer is even.

Examples
4.even?   # => true
3.even?   # => false

odd?

odd? : Bool

Returns true if the integer is odd.

Examples
3.odd?   # => true
4.odd?   # => false

abs

abs : Integer

Returns the absolute value.

Examples
(-5).abs   # => 5
5.abs      # => 5

sqrt

sqrt : Float

Returns the square root as a Float.

Examples
16.sqrt   # => 4.0

modulo

modulo(n: Integer) -> Integer

Returns this modulo n. The result has the same sign as n, consistent with mathematical modulo (not C remainder).

Parameters
n
Examples
7.modulo(3)     # => 1
(-7).modulo(3)  # => 2

in?

in?(range: Range<Integer>) -> Bool

Returns true if the integer falls within range (inclusive).

Parameters
range
Examples
5.in?(1..10)    # => true
11.in?(1..10)   # => false

times

times(block: (Integer -> Void)) -> Void

Calls f exactly this times, passing the current index (0-based).

Parameters
f
Examples
3.times { |i| IO.printLine(i) }   # prints 0, 1, 2

floor

floor : Integer

Returns the greatest integer ≤ this. No-op on integers.

ceil

ceil : Integer

Returns the smallest integer ≥ this. No-op on integers.

round

round : Integer

Rounds to the nearest integer. No-op on integers.

From Monoid

repeat
Combines this value with itself n times.

Defined in other modules

type Float

Implements Blankable, Truthyable.

abs

abs : Float

Returns the absolute value.

Examples
(-3.14).abs   # => 3.14

sqrt

sqrt : Float

Returns the square root.

Examples
25.0.sqrt   # => 5.0

in?

in?(range: Range<Float>) -> Bool

Returns true if the float falls within range (inclusive).

Parameters
range
Examples
1.5.in?(1.0..2.0)   # => true

floor

floor : Integer

Returns the greatest integer ≤ this.

ceil

ceil : Integer

Returns the smallest integer ≥ this.

round

round : Integer

Rounds to the nearest integer.

toInteger

toInteger : Integer

Truncates toward zero, converting to an Integer.

Defined in other modules

module Integer

parse

parse(s: String) -> Result<Integer, ParseError>
parse(s: String, radix: Integer) -> Result<Integer, ParseError>

Parses s in base radix (2..36), e.g. Integer.parse("ff", radix: 16). Digits above 9 are accepted in either case.

parsePrefix

parsePrefix(s: String) -> (Integer, String)?

module Float

parsePrefix

parsePrefix(s: String) -> (Float, String)?

module Number