Skip to content

Change the overflow behavior of floating-point inits from String #25313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions stdlib/public/SwiftShims/RuntimeShims.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,15 @@ SWIFT_RUNTIME_STDLIB_API
void *_swift_objCMirrorSummary(const void * nsObject);

/// Call strtold_l with the C locale, swapping argument and return
/// types so we can operate on Float80. Return NULL on overflow.
/// types so we can operate on Float80.
SWIFT_RUNTIME_STDLIB_API
const char *_swift_stdlib_strtold_clocale(const char *nptr, void *outResult);
/// Call strtod_l with the C locale, swapping argument and return
/// types so we can operate consistently on Float80. Return NULL on
/// overflow.
/// types so we can operate consistently on Float80.
SWIFT_RUNTIME_STDLIB_API
const char *_swift_stdlib_strtod_clocale(const char *nptr, double *outResult);
/// Call strtof_l with the C locale, swapping argument and return
/// types so we can operate consistently on Float80. Return NULL on
/// overflow.
/// types so we can operate consistently on Float80.
SWIFT_RUNTIME_STDLIB_API
const char *_swift_stdlib_strtof_clocale(const char *nptr, float *outResult);

Expand Down
4 changes: 0 additions & 4 deletions stdlib/public/stubs/Stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,6 @@ static const char *_swift_stdlib_strtoX_clocale_impl(
errno = 0;
const auto result = posixImpl(nptr, &EndPtr, getCLocale());
*outResult = result;
if (result == huge || result == -huge || result == 0.0 || result == -0.0) {
if (errno == ERANGE)
EndPtr = nullptr;
}
return EndPtr;
}

Expand Down
16 changes: 5 additions & 11 deletions test/stdlib/NumericParsing.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,11 @@ tests.test("${Self}/Basics") {
expectNil(${Self}("0 ")) // Trailing whitespace
expectNil(${Self}("\u{1D7FF}")) // MATHEMATICAL MONOSPACE DIGIT NINE

// Overflow and underflow. Interleave with other checks to make
// sure we're not abusing errno
expectEqual(0.0, ${Self}("0"))
expectNil(${Self}("2e99999999999999"))
expectEqual(0.0, ${Self}("0"))
expectNil(${Self}("2e-99999999999999"))
expectEqual(0.0, ${Self}("0"))
expectNil(${Self}("-2e99999999999999"))
expectEqual(0.0, ${Self}("0"))
expectNil(${Self}("-2e-99999999999999"))
expectEqual(0.0, ${Self}("0"))
// Overflow and underflow.
expectEqual(.infinity, ${Self}("2e99999999999999"))
expectEqual(-.infinity, ${Self}("-2e99999999999999"))
expectEqual(0, ${Self}("2e-99999999999999"))
expectEqual(0, ${Self}("-2e-99999999999999"))
}

% if Self == 'Float80':
Expand Down