round-to-odd ( x -- y ) (original) (raw)

Vocabulary
math.functions

Inputs

x a real

Outputs

y a whole real number

Word description
Outputs the whole number closest to x, rounding out at half, breaking ties towards odd numbers.

Notes
The result is not necessarily an integer.

Examples

USING: math.functions prettyprint ; 0.5 round-to-odd .
1.0

USING: math.functions prettyprint ; 1.5 round-to-odd .
1.0

Definition

IN: math.functions

GENERIC: round-to-odd ( x -- y )

Methods

USING: math math.functions ;

M: float round-to-odd [ (round-to-odd?) ] (float-round) ;

USING: math math.functions ;

M: integer round-to-odd ; inline

USING: math math.functions ;

M: ratio round-to-odd [ (round-to-odd?) ] (ratio-round) ;