6.17. kink/NUM_DIV¶
6.17.1. type num_div¶
`num_div` is a tuple (Dividend, Divisor), where where Dividend is a `num`, and Divisor is a non-zero `num`. A `num_div` value represents a division of `Dividend` by `Divisor`.
`num_div` values are usually made by Num.op_div or Num.round methods.
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
6.17.1.1. Num_div.dividend¶
`dividend` returns `Dividend` attribute.
Example
:D <- 1.2 / 3.4
stdout.print_line(D.dividend.repr) # => 1.2
6.17.1.2. Num_div.divisor¶
`divisor` returns `Divisor` attribute.
Example
:D <- 1.2 / 3.4
stdout.print_line(D.divisor.repr) # => 3.4
6.17.1.3. Num_div.ceil(Scale)¶
`ceil` rounds the result of the division toward plus infinity.
The result is the smallest `num` with the given `Scale` not less than the real number of the division.
Precondition
`Scale` must be an integer `num`.
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
6.17.1.4. Num_div.floor(Scale)¶
`floor` rounds the result of the division toward minus infinity.
The result is the biggest `num` with the given `Scale` not more than the real number of the division.
Precondition
`Scale` must be an integer `num`.
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
6.17.1.5. Num_div.half_ceil(Scale)¶
`half_ceil` rounds the result of the division toward the nearest `num` with the given `Scale` with tie-breaking toward plus infinity.
The result is the `num` with the given `Scale` nearest to the real number of the division. If there are two such `num` values, the bigger one is returned.
Precondition
`Scale` must be an integer `num`.
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
6.17.1.6. Num_div.half_floor(Scale)¶
`half_floor` rounds the result of the division toward the nearest `num` with the given `Scale` with tie-breaking toward minus infinity.
The result is the `num` with the given `Scale` nearest to the real number of the division. If there are two such `num` values, the smaller one is returned.
Precondition
`Scale` must be an integer `num`.
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
6.17.1.7. Num_div.half_even(Scale)¶
`half_even` performs bankers’ rounding to the result of the division.
The result is the `num` value with the given `Scale` nearest to the real number of the division. If there are two such `num` values, the value with an even `Mantissa` is returned.
Precondition
`Scale` must be an integer `num`.
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
6.17.2. NUM_DIV.new(Dividend Divisor)¶
`new` returns a `num_div` value 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
6.17.3. NUM_DIV.is?(Val)¶
`is?` returns whether `Val` is a `num_div` value.