MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | SYNOPSIS |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 2 | int to_int(string) |
| 3 | int to_int(float) |
| 4 | int to_int(int) |
| 5 | int to_int(closure) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 6 | |
| 7 | (int)<value> |
| 8 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 9 | DESCRIPTION |
| 10 | Floats are truncated to integer values, strings with leadings |
| 11 | digits are converted to integers up to the first non-digit. |
| 12 | lfun-closures are converted into their function index (not adjusted |
| 13 | for inheritance), variable closure are converted into their variable |
| 14 | index. |
| 15 | Integers are just returned. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 16 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 17 | Regarding floats, it is important to keep rounding effects |
| 18 | in mind: to_int(3.1*10.0) does not return 31, but instead 30, |
| 19 | because internally the result of the multiplication is 30.999999. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 20 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 21 | The function supports the '0x', '0o' and '0b' base prefixes. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 22 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 23 | BUGS |
| 24 | The cast notation only works if the precise type of <value> |
| 25 | is known at compile-time. This will not be fixed - use the |
| 26 | function form instead. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 27 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 28 | HISTORY |
| 29 | Introduced in 3.2.1@2. |
| 30 | LDMud 3.2.11/3.3.611 added support for the base prefixes. |
| 31 | |
| 32 | SEE ALSO |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 33 | to_string(E), sscanf(E) |