Hi,

21.5p4 and 21.5p11 say that std::stof() and std::stod() are both supposed
to call strtod() (for char*) or wcstod() (for wchar_t*). libc++ currently
calls strtof() / wcstof() from std::stof(), so the attached patch fixes
this.

This has a surprising effect: 21.5p6 and 21.5p13 say that stof() should
throw out_of_range if strtod / wcstod set errno to ERANGE. Now, for
stof("1.e60") will call strtod("1.e60", ...). 1.e60 fits in a double, so
strtod() won't set ERANGE. But stof() returns a float, and this double
converted to a float does result in INFINITY. So it sounds like the
standard demands that stof("1.e60") returns INFINITY but does not throw,
while std::stod("1.e360") is supposed to return INFINITY and
throw out_of_range (assuming the C library sets ERANGE in this case, which
seems like a reasonable assumption.)

So I'm not sure if the standard is specifying what it intends to specify
here. If someone familiar with DRs could report, that'd be cool.

Nevertheless, the attached patch makes libc++ do what the standard demands
(and updates one test).

Nico

Attachment: libcxx-stof.patch
Description: Binary data

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to