Decimal's nextUp and nextDown ignore precision

let decimal = Decimal(string: "0.000499")
decimal.nextUp  //  0.000500
decimal.nextUp  //  0.000600

The least representable value that compares greater than this value.

Why decimal's nextUp is ignoring the precision?

Expect:

let decimal = Decimal(string: "0.000499")
decimal.nextUp  //  0.000500
decimal.nextUp  //  0.000501

What extra work I need to do at this case?

Possible bugs of Decimal.ulp and Decimal.nextUp were mentioned here:

I fixed this for the open-source version (swift-corelibs-foundation) but Apple hasn’t picked up the changes for the proprietary version shipped on their platforms :man_shrugging:

8 Likes

Maybe compatibility tests with Darwin, that should fail, could draw attention this issue.

Is there any workaround for now ?

I suppose you could copy and paste the corrected code into your own project.