Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Bug in plugin ROUND function

From: joseantoniorocha::gmail::com at: 12-Jan-2007 17:13

There is a bug in puglin ROUND function: The ROUND in plugin: round: func [ [catch] n [number! money! time!] /even /down /half-down /floor /ceiling /half-ceiling /to scale [number! money! time!] /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,.0 * 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,.0 0,.0] ceiling ] either ceiling [n + mod negate n scale] [n - mod n scale] ] ] ] ROUND in VIEW: 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] ] ] ] -- nome: "José Antonio Meira da Rocha" tratamento: "Prof. MS." atividade: "Ensino e pesquisa em mídias digitais" googletalk: email: MSN: joseantoniorocha-gmail.com site: http://meiradarocha.jor.br ICQ: 658222 Skype: "meiradarocha_jor"