Revert "Replace std::stof with std::strtof."
This reverts commit 5f9996dc9c
.
Reason for revert: Issues around locale, will be revisited in a different fashion.
Original change's description:
> Replace std::stof with std::strtof.
>
> std::stof can throw std::out_of_range if the input is not actually
> representable. We had similar code in Skia which was using stof to
> test that a stringized float would round-trip successfully, and it
> would throw an exception on some older versions of libc++ for edge-
> case inputs like FLT_MIN.
>
> std::stof is documented as using strtof to do its conversion, so this
> shouldn't change your results in practice; it just removes the part
> where it could potentially throw for some inputs.
>
> Tangentially, have you ever seen a case where the scientific-notation
> path gets used? According to brucedawson@, nine digits should always
> safely round-trip (in 2013, testing gcc and MSVC). See
> https://randomascii.wordpress.com/2013/02/07/float-precision-revisited-nine-digit-float-portability/
>
> Change-Id: Ie215fb8502dd8c554020c6f73432f91e3d756563
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/104500
> Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
> Auto-Submit: John Stiles <johnstiles@google.com>
> Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
> Commit-Queue: John Stiles <johnstiles@google.com>
TBR=dsinclair@chromium.org,johnstiles@google.com,noreply+kokoro@google.com,dawn-scoped@luci-project-accounts.iam.gserviceaccount.com,dsinclair@google.com
Change-Id: I825f5677f98dea1a13b6423ec18ae3a1e750ce09
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/104502
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
0c2909e4d4
commit
2a3eae7371
|
@ -15,7 +15,6 @@
|
|||
#include "src/tint/writer/float_to_string.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <iomanip>
|
||||
|
@ -36,7 +35,7 @@ std::string FloatToString(float f) {
|
|||
|
||||
// If this string can be parsed without loss of information, use it
|
||||
auto float_equal_no_warning = std::equal_to<float>();
|
||||
if (float_equal_no_warning(std::strtof(fixed.str().c_str(), nullptr), f)) {
|
||||
if (float_equal_no_warning(std::stof(fixed.str()), f)) {
|
||||
auto str = fixed.str();
|
||||
while (str.length() >= 2 && str[str.size() - 1] == '0' && str[str.size() - 2] != '.') {
|
||||
str.pop_back();
|
||||
|
|
Loading…
Reference in New Issue