Skip to content

[SR-6671] Decimal.leastNonzeroMagnitude, leastNormalMagnitude should have -128 exponent #1386

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

Conversation

takasek
Copy link
Contributor

@takasek takasek commented Dec 28, 2017

@takasek
Copy link
Contributor Author

takasek commented Dec 28, 2017

@swift-ci please test

@parkera
Copy link
Contributor

parkera commented Jan 2, 2018

This one is shared with the overlay so we should make coordinated changes there if we go forward with it.

@phausler
Copy link
Contributor

phausler commented Jan 2, 2018

Can we add some tests for this to verify the expected behavior?

@takasek
Copy link
Contributor Author

takasek commented Jan 3, 2018

we should make coordinated changes there

Do you mean that these codes should be fixed at the same time?

https://github.com/apple/swift/blob/49a8cf050304e3503960f0f1815afafe71dba28a/test/stdlib/TestDecimal.swift#L130-L133
https://github.com/apple/swift/blob/8f8f00012a391b7c254e2056ef382c768ca7671a/stdlib/public/SDK/Foundation/Decimal.swift#L22-L23

Can we add some tests for this to verify the expected behavior?

Sure, please add them.

@parkera
Copy link
Contributor

parkera commented Jan 3, 2018

@takasek I think @phausler was asking for you to write some additional tests and include them in this PR.

@takasek
Copy link
Contributor Author

takasek commented Jan 5, 2018

OK, I'll add some tests.

XCTAssertEqual(try trySerialize([-Decimal.leastNonzeroMagnitude]), "[-0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001]")
XCTAssertEqual(try trySerialize([Decimal.leastNonzeroMagnitude]), "[0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001]")
XCTAssertEqual(try trySerialize([-Decimal.leastNonzeroMagnitude]), "[-0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001]")
XCTAssertEqual(try trySerialize([Decimal.leastNonzeroMagnitude]), "[0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001]")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests failed because of changes in this PR.

@@ -101,31 +101,31 @@ public struct Decimal {

extension Decimal {
public static let leastFiniteMagnitude = Decimal(
_exponent: 127,
_exponent: Int32(Int8.max),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of such expression change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's going on here, and where did this property come from? "Magnitudes" are always non-negative, but this is a huge negative number. I don't know why this property even exists, but the name and documentation are extremely misleading.

(@takasek This is tangential to your change, but this is the first I've seen this).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I haven't been respond for long time...

Referring to the code, _exponent has a precondition to conform Int8. I intend to describe the precondition.
https://github.com/apple/swift-corelibs-foundation/blob/a40cc5cb3159bf64d70cb657131a01272dc988e3/Foundation/Decimal.swift#L22-L28

More fundamental solution is to change public var _exponent: Int32 into public var _exponent: Int8 but I have no idea of the impact.

@millenomi
Copy link
Contributor

@swift-ci Please test.

@alblue
Copy link
Contributor

alblue commented Jan 25, 2018

@phausler @parkera can you check this over - are the added tests sufficient?

@millenomi
Copy link
Contributor

Are the objections above understood? Do they still need correction?

@alblue
Copy link
Contributor

alblue commented Nov 8, 2018

This seems to have gone stale. Is it still needed, or can it be closed?

@spevans
Copy link
Contributor

spevans commented Nov 24, 2018

@swift-ci test

@takasek
Copy link
Contributor Author

takasek commented Jan 1, 2019

Any problem still on this issue?

@alblue
Copy link
Contributor

alblue commented Jan 14, 2019

@swift-ci test

# Conflicts:
#	TestFoundation/TestDecimal.swift
@takasek
Copy link
Contributor Author

takasek commented Mar 23, 2019

This issue is yet stale.
NSDecimalNumber defines its exponent's range is down to -128.
https://developer.apple.com/documentation/foundation/nsdecimalnumber
Thus Foundation.Decimal should follow it.

@shahmishal shahmishal closed this Oct 6, 2020
@shahmishal
Copy link
Member

The Swift project moved the default branch to main and deleted master branch, so GitHub automatically closed the PR. Please re-create pull request with main branch.

More detail about the branch update - https://forums.swift.org/t/updating-branch-names/40412

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants