Function Entry: ATOI
← Prev | ↑ Chapter | Next → | Index | Symbols
Function Entry: ATOI
Name
atoi
Class
Conversion Function
Syntax
(atoi string)
Arguments and Values
string: a string representing any number.
Description
Converts string into an integer. Trailing non-numeric characters terminate parsing; the integer prefix is returned as the value. Decimal-fraction input is truncated toward zero.
Return Values
An integer; 0 if the string is not a valid number.
Side Effects
None.
Examples
(atoi "12")returns12.(atoi "12.34")returns12(truncating decimal input).(atoi "xyz")returns0.
Implementation-defined Behaviour
The Phase-5 vendor citations below define the documented surface. Several lexical edges are not nailed down by either vendor's prose and remain implementation-defined unless and until product tests exist:
- Leading whitespace handling (
(atoi " 17")). - Sign acceptance (
(atoi "+17"),(atoi "-17")). - Behaviour of leading-zero forms (
(atoi "017")— decimal vs. octal-like). - Behaviour of
0x-prefixed forms ((atoi "0xbabe")). - Trailing-junk strictness (
(atoi "17x")).
For clautolisp the chosen lex model is: skip leading whitespace, accept optional sign, parse the longest run of decimal digits, truncate the fractional part if a . follows the digit run, treat all leading-zero forms as base 10, treat 0x-prefixed forms as 0 (no autodetection). The probe suite in probe-atoi.lsp records the AutoCAD / BricsCAD product behaviour when run via scripts/run-probes.sh.
Tested Behaviour (BricsCAD V26 / macOS, 2026-04-26)
The probe suite was run against BricsCAD V26 on macOS via the direct runner. Results from results/bricscad/macos/20260426T122808Z/results.sexp:
| Probe | Returned |
|---|---|
(atoi "17") |
17 |
(atoi "017") |
17 (decimal interpretation; not octal) |
(atoi "0xbabe") |
0 (0x-prefix rejected) |
(atoi "+17") |
17 (leading + accepted) |
(atoi "-17") |
-17 (leading - accepted) |
(atoi "17x") |
17 (parsing stops at first non-digit) |
(atoi " 17") |
17 (leading whitespace accepted) |
(atoi "3.9") |
3 (decimal-fraction truncates toward zero) |
Confirms a strtol(…, 10)-style C-library model: skip leading whitespace, optional sign, longest decimal-digit prefix, return zero on no digits. The tested behaviour matches clautolisp's implementation choice, so the lex edges previously marked implementation-defined are now tested on BricsCAD V26.
Availability
- AutoCAD 2026: documented (Autodesk reference page).
- BricsCAD V26: documented + product-tested on macOS (probe suite, 2026-04-26).
- Status: documented in both vendors; lex-edge behaviour now tested against BricsCAD V26 / macOS. AutoCAD product test deferred until a local install becomes available.
See Also
- probe-atoi.lsp — executable Phase-5 probe suite.
itoa— integer-to-string companion.
Source Notes
- [atoi (AutoLISP 2026)](https://help.autodesk.com/cloudhelp/2026/ENU/AutoCAD-AutoLISP-Reference/files/GUID-20EF237C-7079-4E29-860C-B8531D6C7F36.htm)
- [atoi (BricsCAD V26 DevRef)](https://developer.bricsys.com/bricscad/help/en_US/V26/DevRef/source/atoi.htm)
- Status: documented (Phase 5 closure via vendor citation; product-test coverage deferred until a CAD product is available locally).