4.17. kink/NUM_DIV

The companion mod for num_div vals.

4.17.1. type num_div

A num_div val (Dividend, Divisor) represents a division of Dividend by Divisor, where Dividend is a num, and Divisor is a non-zero num.

Num_div vals are usually made by Num.op_div or Num.round.

Example:

:NUM_DIV.require_from('kink/')
stdout.print_line(NUM_DIV.new(10 3).ceil(3).repr)   # => 0.334
stdout.print_line(NUM_DIV.new(10 3).floor(3).repr)  # => 0.333

stdout.print_line((10 / 3).ceil(3).repr)  # => 0.334
stdout.print_line((10 / 3).floor(3).repr) # => 0.333

stdout.print_line(1.23456.round.ceil(3).repr)   # => 1.235
stdout.print_line(1.23456.round.floor(3).repr)  # => 1.234

4.17.1.1. Num_div.dividend

Num_div.dividend returns Dividend of the Num_div.

The result is a num.

Example:

:D <- 1.2 / 3.4
stdout.print_line(D.dividend.repr)  # => 1.2

4.17.1.2. Num_div.divisor

Num_div.divisor returns Divisor of the Num_div.

The result is a num.

Example:

:D <- 1.2 / 3.4
stdout.print_line(D.divisor.repr)  # => 3.4

4.17.1.3. Num_div.ceil(Scale)

Num_div.ceil does toward-plus-infinity rounding to the result of the division.

Precondition:

• Scale must be an int num

The result is the smallest num with the Scale not less than the result of the division.

Example:

stdout.print_line((-0.16).round.ceil(1).repr) # => (-0.1)
stdout.print_line((-0.15).round.ceil(1).repr) # => (-0.1)
stdout.print_line((-0.14).round.ceil(1).repr) # => (-0.1)

stdout.print_line((-0.06).round.ceil(1).repr) # => 0.0
stdout.print_line((-0.05).round.ceil(1).repr) # => 0.0
stdout.print_line((-0.04).round.ceil(1).repr) # => 0.0

stdout.print_line(0.04.round.ceil(1).repr)  # => 0.1
stdout.print_line(0.05.round.ceil(1).repr)  # => 0.1
stdout.print_line(0.06.round.ceil(1).repr)  # => 0.1

stdout.print_line(0.14.round.ceil(1).repr)  # => 0.2
stdout.print_line(0.15.round.ceil(1).repr)  # => 0.2
stdout.print_line(0.16.round.ceil(1).repr)  # => 0.2

4.17.1.4. Num_div.floor(Scale)

Num_div.floor does toward-minus-infinity rounding to the result of the division.

Precondition:

• Scale must be an int num

The result is the biggest num with the Scale not more than the result of the division.

Example:

stdout.print_line((-0.16).round.floor(1).repr)  # => (-0.2)
stdout.print_line((-0.15).round.floor(1).repr)  # => (-0.2)
stdout.print_line((-0.14).round.floor(1).repr)  # => (-0.2)

stdout.print_line((-0.06).round.floor(1).repr)  # => (-0.1)
stdout.print_line((-0.05).round.floor(1).repr)  # => (-0.1)
stdout.print_line((-0.04).round.floor(1).repr)  # => (-0.1)

stdout.print_line(0.04.round.floor(1).repr) # => 0.0
stdout.print_line(0.05.round.floor(1).repr) # => 0.0
stdout.print_line(0.06.round.floor(1).repr) # => 0.0

stdout.print_line(0.14.round.floor(1).repr) # => 0.1
stdout.print_line(0.15.round.floor(1).repr) # => 0.1
stdout.print_line(0.16.round.floor(1).repr) # => 0.1

4.17.1.5. Num_div.half_ceil(Scale)

Num_div.half_ceil does toward-nearest rounding to the result of the division with tie-breaking toward plus infinity.

Precondition:

• Scale must be an int num

The result is the num with the Scale nearest to the result of the division. If there are two such nums, the bigger one is returned.

Example:

stdout.print_line((-0.16).round.half_ceil(1).repr)  # => (-0.2)
stdout.print_line((-0.15).round.half_ceil(1).repr)  # => (-0.1)
stdout.print_line((-0.14).round.half_ceil(1).repr)  # => (-0.1)

stdout.print_line((-0.06).round.half_ceil(1).repr)  # => (-0.1)
stdout.print_line((-0.05).round.half_ceil(1).repr)  # => 0.0
stdout.print_line((-0.04).round.half_ceil(1).repr)  # => 0.0

stdout.print_line(0.04.round.half_ceil(1).repr) # => 0.0
stdout.print_line(0.05.round.half_ceil(1).repr) # => 0.1
stdout.print_line(0.06.round.half_ceil(1).repr) # => 0.1

stdout.print_line(0.14.round.half_ceil(1).repr) # => 0.1
stdout.print_line(0.15.round.half_ceil(1).repr) # => 0.2
stdout.print_line(0.16.round.half_ceil(1).repr) # => 0.2

4.17.1.6. Num_div.half_floor(Scale)

Num_div.half_floor does toward-nearest rounding to the result of the division with tie-breaking toward minus infinity.

Precondition:

• Scale must be an int num

The result is the num with the Scale nearest to the result of the division. If there are two such nums, the smaller one is returned.

Example:

stdout.print_line((-0.16).round.half_floor(1).repr) # => (-0.2)
stdout.print_line((-0.15).round.half_floor(1).repr) # => (-0.2)
stdout.print_line((-0.14).round.half_floor(1).repr) # => (-0.1)

stdout.print_line((-0.06).round.half_floor(1).repr) # => (-0.1)
stdout.print_line((-0.05).round.half_floor(1).repr) # => (-0.1)
stdout.print_line((-0.04).round.half_floor(1).repr) # => 0.0

stdout.print_line(0.04.round.half_floor(1).repr)  # => 0.0
stdout.print_line(0.05.round.half_floor(1).repr)  # => 0.0
stdout.print_line(0.06.round.half_floor(1).repr)  # => 0.1

stdout.print_line(0.14.round.half_floor(1).repr)  # => 0.1
stdout.print_line(0.15.round.half_floor(1).repr)  # => 0.1
stdout.print_line(0.16.round.half_floor(1).repr)  # => 0.2

4.17.1.7. Num_div.half_even(Scale)

Num_div.half_even does bankers’ rounding to the result of the division.

Precondition:

• Scale must be an int num

The result is the num with the Scale nearest to the result of the division. If there are two such nums, the num with an even Mantissa is returned.

Example:

stdout.print_line((-0.16).round.half_even(1).repr)  # => (-0.2)
stdout.print_line((-0.15).round.half_even(1).repr)  # => (-0.2)
stdout.print_line((-0.14).round.half_even(1).repr)  # => (-0.1)

stdout.print_line((-0.06).round.half_even(1).repr)  # => (-0.1)
stdout.print_line((-0.05).round.half_even(1).repr)  # => 0.0
stdout.print_line((-0.04).round.half_even(1).repr)  # => 0.0

stdout.print_line(0.04.round.half_even(1).repr) # => 0.0
stdout.print_line(0.05.round.half_even(1).repr) # => 0.0
stdout.print_line(0.06.round.half_even(1).repr) # => 0.1

stdout.print_line(0.14.round.half_even(1).repr) # => 0.1
stdout.print_line(0.15.round.half_even(1).repr) # => 0.2
stdout.print_line(0.16.round.half_even(1).repr) # => 0.2

4.17.1.8. Num_div.repr

Num_div.repr returns a str such as "(1.2/(-3.4))"

4.17.2. NUM_DIV.new(Dividend Divisor)

NUM_DIV.new makes a num_div val with (Dividend, Divisor).

Preconditions:

• Dividend must be a num

• Divisor must be a num

• Divisor must not be equal to 0

Example:

:NUM_DIV.require_from('kink/')
stdout.print_line(NUM_DIV.new(10 3).ceil(3).repr)   # => 0.334
stdout.print_line(NUM_DIV.new(10 3).floor(3).repr)  # => 0.333

4.17.3. NUM_DIV.is?(Val)

NUM_DIV.is? returns whether Val is a num_div val.