Difference between revisions of "Rounding"
(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 | + | *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.
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.