Skip to content

Fix a bug in root and add a test case for it. #25326

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

Merged
merged 1 commit into from
Jun 10, 2019
Merged
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
2 changes: 1 addition & 1 deletion stdlib/public/core/MathFunctions.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ extension ${Self}: ElementaryFunctions {
guard x >= 0 || n % 2 != 0 else { return .nan }
// TODO: this implementation isn't quite right for n so large that
// the conversion to `${Self}` rounds.
return ${Self}(signOf: x, magnitudeOf: pow(x, 1/${Self}(n)))
return ${Self}(signOf: x, magnitudeOf: pow(x.magnitude, 1/${Self}(n)))
}

@_alwaysEmitIntoClient
Expand Down
2 changes: 1 addition & 1 deletion test/stdlib/MathFunctions.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ internal extension ElementaryFunctions where Self: BinaryFloatingPoint {
expectEqualWithTolerance(-1.415037499278843818546261056052183491, Self.log2(0.375))
expectEqualWithTolerance(0.3184537311185346158102472135905995955, Self.log1p(0.375))
expectEqualWithTolerance(-0.425968732272281148346188780918363771, Self.log10(0.375))
expectEqualWithTolerance(0.7211247851537041911608191553900547941, Self.root(0.375, 3))
expectEqualWithTolerance(-0.7211247851537041911608191553900547941, Self.root(-0.375, 3))
expectEqualWithTolerance(0.6123724356957945245493210186764728479, Self.sqrt(0.375))
expectEqualWithTolerance(0.54171335479545025876069682133938570, Self.pow(0.375, 0.625))
expectEqualWithTolerance(-0.052734375, Self.pow(-0.375, 3))
Expand Down