Jump to content
Toggle menu
  • 3.1K articles
  • 4.4K files
  • 18 users
  • 91.5K edits
Ashenzari's Archive
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Rounding: Difference between revisions

From Ashenzari's Archive
Hordes (talk | contribs)
a short page on the subject
 
Hordes (talk | contribs)
mNo edit summary
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 05:39, 9 November 2025

Version 0.33: This article may not be up to date for the latest stable release of Crawl.

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.

Contents