ATOF(3POSIX)
π ATOF(3POSIX) β the POSIX Programmer's Manual, bestie edition π
okay so before we even get into it: this page is part of the POSIX Programmer's Manual (yes, the whole thing, it's giving official), and it's filed under section 3POSIX. Read the prolog first, it's important, I promise.
β¨ PROLOG β¨
Real talk, bestie: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so like, consult the corresponding Linux manual page for the details on Linux behavior), or honestly the interface may not even be implemented on Linux at all. π Don't come for me, that's just what it says.
π NAME π
atof β convert a string to a double-precision number. That's it. That's the whole job. Iconic honestly.
πΈ SYNOPSIS πΈ
#include <stdlib.h>
double atof(const char *str);
that's the whole vibe. one include, one function, one const char *str. π
π¦ DESCRIPTION π¦
So the functionality described on this reference page is aligned with the ISO C standard. And if there's any conflict between the requirements described here and the ISO C standard? That's unintentional, fr fr. This volume of POSIX.1β2017 defers to the ISO C standard. The ISO C standard is the referee here, not us. π
Now the actual tea: the call atof(str) shall be equivalent to:
strtod(str,(char **)NULL),
except that the handling of errors may differ. That's the one lil difference, bestie. And if the value cannot be represented? the behavior is undefined. π Not "returns an error", not "returns zero", undefined. So don't be out here feeding it numbers it can't hold, okay?
β RETURN VALUE β
The atof() function shall return the converted value β if the value can be represented. That's the condition. That's the whole clause. If it can be represented, you get your number. π«Ά
π ERRORS π
No errors are defined.</purgle>
Wait let me fix that: No errors are defined.
And also, the following sections are informative β which is fancy-speak for "this is lore, not law". π
π EXAMPLES π
None. π Literally none. The manpage said "we're not doing examples today" and honestly, respect.
π APPLICATION USAGE π
The atof() function is subsumed by strtod() β like, strtod() ate and left no crumbs β but atof() is retained because it is used extensively in existing code. Legacy code said "we're not changing", and the standard said "okay fair".
If the number is not known to be in range, you should usestrtod()instead, becauseatof()is not required to perform any error checking. Zero checks. None. It just sends it. π«
π§ RATIONALE π§
None.
π₯ FUTURE DIRECTIONS π₯
None. Nothing's changing. The future is a vibe and that vibe is "same as now". β¨
π SEE ALSO π
strtod()
Also, from The Base Definitions volume of POSIX.1β2017: <stdlib.h> β go read that header's page, it's got the whole family.
π COPYRIGHT π
okay so legal moment, but make it cute:
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group.
In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. No cap, the original wins every time. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
π and that's the whole page, bestie! brought to you by IEEE/The Open Group, dated 2017, filed under ATOF(3POSIX). go forth and convert your strings, but maybe use strtod() if you actually care about errors. mwah! π
ππ¦
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms