Skip to content
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

[SR-15134] Decimal.init(sign:exponent:significand:) gives incorrect values when exponent overflow or underflows #3360

Closed
xwu opened this issue Aug 29, 2021 · 1 comment
Assignees

Comments

@xwu
Copy link
Collaborator

xwu commented Aug 29, 2021

Previous ID SR-15134
Radar None
Original Reporter @xwu
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee @xwu
Priority Medium

md5: 90fff27aa26c010ed376b88af6f68045

relates to:

  • SR-15132 Decimal.significand gives wrong sign for negative values

Issue Description:

Consider the following behavior of Double:

let x = Double.leastNonzeroMagnitude
print(Double(sign: .plus, exponent: -10, significand: x)) // 0.0
let y = Double.greatestFiniteMagnitude
print(Double(sign: .plus, exponent: 10, significand: y)) // inf

Unfortunately, Decimal does not consider what happens when exponents are incremented out of range, and the result is dramatically wrong:

import Foundation
let a = Decimal.leastNonzeroMagnitude
print(Decimal(sign: .plus, exponent: -10, significand: a))
// 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
let b = Decimal.greatestFiniteMagnitude
print(Decimal(sign: .plus, exponent: 10, significand: b))
// 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000340282366920938463463374607431768211455
@xwu
Copy link
Collaborator Author

xwu commented Aug 31, 2021

#3068

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant