Meanders.Tools
Meanders · Utilities

ME Round to Odd/Even

ME Odd/Even · v0.1.0

Round numbers to the nearest odd or even integer.

Overview

Description

Rounds one or more numbers to the nearest integer with a specified odd or even parity. Mode 0 selects an even result and Mode 1 selects an odd result.

Input Parameters

Inputs

2 parameters

Number

N

Numbers to round to the nearest integer with the requested parity.

numberlist

Mode

Moptional

Requested integer parity. 0 = Even, 1 = Odd. If the list is shorter than Number, its last value is repeated.

integerlist
Output Parameters

Outputs

1 parameter

Rounded

R

Numbers rounded to the nearest integer with the requested odd or even parity.

numberlist
Usage

Examples

Round to even

Round numbers to the nearest even integer.

Input
[1.2, 2.7, 3.4] with M = 0
Output
[2, 2, 4]

Round to odd

Round numbers to the nearest odd integer.

Input
[1.2, 2.7, 3.4] with M = 1
Output
[1, 3, 3]

Mode list with Repeat Last

When the Mode list is shorter than Number, the last Mode value is repeated. Extra Mode values are ignored.

Input
Number = [1.2, 2.7, 3.4, 4.9], Mode = [0, 1]
Output
[2, 3, 4, 5]
Additional Information

Notes

  • Mode 0 means Even.
  • Mode 1 means Odd.
  • Number is the master list and determines the number of output items.
  • If Mode contains fewer items than Number, the last Mode value is repeated.
  • If Mode contains more items than Number, extra Mode values are ignored.
  • The output always contains the same number of items as the Number input.
  • For values exactly halfway between two valid integers, the nearest valid integer is selected according to the requested parity.
  • The Number input accepts a list of numbers.
Validation

Errors

  • !Mode must be 0 (Even) or 1 (Odd).
  • !Number cannot contain NaN or Infinity.
Explore More

Related Components