Namespaces
Variants
Views
Actions

Talk:cpp/string/byte/strtof

From cppreference.com
< Talk:cpp‎ | string/byte
Revision as of 09:48, 23 March 2021 by Cubbi (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

[edit] Add errno

On success, these functions return the value corresponding to the contents of str.

On failure, errno gets set to a non-0 value and either 0 or ±HUGE_VAL (according to the sign of the value) is returned.

The code example demonstrates checking the value of errno, but the reasoning behind it is not explained.

This need to be incorporated in the page, but in the meantime, the C11 standard here says "If the correct value overflows and default rounding is in effect ... the value of the macro ERANGE is stored in errno. If the result underflows ... whether errno acquires the value ERANGE is implementation-defined" --Ybab321 (talk) 14:39, 22 March 2021 (PDT)
For C functions it's also generally useful to mention how POSIX specifies errno (here: ERANGE for both overflow and underflow and EINVAL when it couldn't convert anything) --Cubbi (talk) 10:48, 23 March 2021 (PDT)