Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikibooksThe Free Textbook Project
Search

Rebol Programming/round

From Wikibooks, open books for an open world
<Rebol Programming
This page may need to bereviewed for quality.

USAGE:

[edit |edit source]
ROUND n /even /down /half-down /floor /ceiling /half-ceiling /to scale

DESCRIPTION:

[edit |edit source]

Returns the nearest integer. Halves round up (away from zero) by default.

ROUND is a function value.

ARGUMENTS

[edit |edit source]
  • n -- The value to round (Type: number money time)

REFINEMENTS

[edit |edit source]
  • /even -- Halves round toward even results
  • /down -- Round toward zero, ignoring discarded digits. (truncate)
  • /half-down -- Halves round toward zero
  • /floor -- Round in negative direction
  • /ceiling -- Round in positive direction
  • /half-ceiling -- Halves round in positive direction
  • /to -- Return the nearest multiple of the scale parameter
    • scale -- Must be a non-zero value (Type: number money time)

(SPECIAL ATTRIBUTES)

[edit |edit source]
  • catch

SOURCE CODE

[edit |edit source]
round: func [    {Returns the nearest integer. Halves round up (away from zero) by default.}     [catch]     n [number! money! time!] "The value to round"     /even "Halves round toward even results"     /down {Round toward zero, ignoring discarded digits. (truncate)}     /half-down "Halves round toward zero"     /floor "Round in negative direction"     /ceiling "Round in positive direction"     /half-ceiling "Halves round in positive direction"     /to "Return the nearest multiple of the scale parameter"     scale [number! money! time!] "Must be a non-zero value"     /local m][    throw-on-error [        scale: abs any [scale 1]         any [number? n scale: make n scale]         make scale either any [even half-ceiling] [            m: 0.5 * scale + n             any [                all [                    m = m: m - mod m scale                     even                     positive? m - n                     m - mod m scale + scale                ]                 m            ]        ] [            any [                floor                 ceiling                 (ceiling: (found? half-down) xor negative? n down)                 n: add n scale * pick [-0.5 0.5] ceiling            ]             either ceiling [n + mod negate n scale] [n - mod n scale]        ]    ]]
Retrieved from "https://en.wikibooks.org/w/index.php?title=Rebol_Programming/round&oldid=3353019"
Category:

[8]ページ先頭

©2009-2025 Movatter.jp