Difference between revisions of "Rounding"

From CrawlWiki
Jump to: navigation, search
(a short page on the subject)
 
m
Line 4: Line 4:
 
*Always round up: Numbers are rounded up.
 
*Always round up: Numbers are rounded up.
 
*Always round down (truncate): Numbers are rounded down, thus ignoring the decimal place. By default, C++ truncates numbers, so if there's no other indication in the code, it'll be rounded down.
 
*Always round down (truncate): Numbers are rounded down, thus ignoring the decimal place. By default, C++ truncates numbers, so if there's no other indication in the code, it'll be rounded down.
*Round half up: 0.5 and up are rounded up, else round down. This may be used for [[range]]s and other numbers that can't feasibly be randomised, bu
+
*Round half up: 0.5 and up are rounded up, else round down. This may be used for ranges and other numbers that can't feasibly be randomised.
 
*Weighted rounding (''rounded in a weighted manner''): The number is tracked, typically to the hundredths place. The decimal place remainder is the % chance to round up. This is very commonly used to avoid hard breakpoints, e.g., spell damage, shield encumbrance, time used to take actions, [[AC]]/[[EV]] all use weighted rounding.
 
*Weighted rounding (''rounded in a weighted manner''): The number is tracked, typically to the hundredths place. The decimal place remainder is the % chance to round up. This is very commonly used to avoid hard breakpoints, e.g., spell damage, shield encumbrance, time used to take actions, [[AC]]/[[EV]] all use weighted rounding.
 
**For example, if you would take 4.30 [[aut]] to move, you instead have a 30% chance to move at 5 aut, and a (100%-30%=) 70% chance to move at 4 aut.
 
**For example, if you would take 4.30 [[aut]] to move, you instead have a 30% chance to move at 5 aut, and a (100%-30%=) 70% chance to move at 4 aut.

Revision as of 06:39, 9 November 2025

Version 0.33: This article is up to date for the latest stable release of Dungeon Crawl Stone Soup.

Crawl uses several types of rounding:

  • Always round up: Numbers are rounded up.
  • Always round down (truncate): Numbers are rounded down, thus ignoring the decimal place. By default, C++ truncates numbers, so if there's no other indication in the code, it'll be rounded down.
  • Round half up: 0.5 and up are rounded up, else round down. This may be used for ranges and other numbers that can't feasibly be randomised.
  • Weighted rounding (rounded in a weighted manner): The number is tracked, typically to the hundredths place. The decimal place remainder is the % chance to round up. This is very commonly used to avoid hard breakpoints, e.g., spell damage, shield encumbrance, time used to take actions, AC/EV all use weighted rounding.
    • For example, if you would take 4.30 aut to move, you instead have a 30% chance to move at 5 aut, and a (100%-30%=) 70% chance to move at 4 aut.
    • If you have 35.5 AC, for each hit, there is a 50% chance for your AC to be treated as 35, and a 50% chance for your AC to be treated as 36.

History

In general, as the versions progressed, more and more things started to use random rounding. For example, [[AC] and EV weren't randomly rounded until 0.33.