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-6671] Decimal.leastNonzeroMagnitude, leastNormalMagnitude should have -128 exponent #4266

Closed
swift-ci opened this issue Dec 28, 2017 · 3 comments
Assignees

Comments

@swift-ci
Copy link
Contributor

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

md5: f8e60ccf11f2fdc6d95d64e7bcbd0e41

relates to:

  • SR-14974 Decimal.ulp produces inaccurate results

Issue Description:

`Decimal.leastNonzeroMagnitude` and `Decimal.leastNormalMagnitude` are set -127 as their exponents.

However, you can make less value than least magnitude by such code below.

func truelyLeastDecimal() -> Decimal {
    var x = Decimal(string: "0.1")!
    var r = Decimal()
    NSDecimalPower(&r, &x, 128, .plain)
    return r
}

func p(_ d: Decimal) {
    print("=====")
    print(d)
    print(d._mantissa)
    print(d._exponent)
}
p(Decimal.leastNormalMagnitude)
p(truelyLeastDecimal())

/*
 =====
 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
 (1, 0, 0, 0, 0, 0, 0, 0)
 -127
 =====
 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
 (1, 0, 0, 0, 0, 0, 0, 0)
 -128
 */

NSDecimalNumber defines its exponent's range is down to -128.
https://developer.apple.com/documentation/foundation/nsdecimalnumber

Thus `Foundation.Decimal` should follow it. Isn't it?

@swift-ci
Copy link
Contributor Author

Comment by Yoshitaka Seki (JIRA)

I just submitted #1386 .

@weissi
Copy link
Member

weissi commented Apr 13, 2021

this still crashes on main:

 40> truelyLeastDecimal()
$R3: Decimal = 0.000000

 41> print(truelyLeastDecimal()) 
0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
 42> p(truelyLeastDecimal())
Execution interrupted. Enter code to recover and continue.
Enter LLDB commands to investigate (type :help for assistance.)

@xwu
Copy link
Collaborator

xwu commented Aug 30, 2021

#3067

@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

3 participants