Decimal vs Double inconsistency

I noticed some inconsistency regarding how NaN is handled for Decimal and Double31
Does anyone know why is it so?

1 Like

NaN on a Decimal is represented as the value 0 with a negative sign flag. So I’d say that it’s a bug that it’s abs value is 0.
Previously Decimal had a bug where negating 0 would give NaN and vice versa.

3 Likes

Sorry, I meant to follow up on this, @Eugene_Gubin:

If you are interested in contributing towards solving this issue, there are a couple of things you could do:

  1. Write a bug report
  2. Attempt fixing the issue yourself and create a PR with the fix.

I don’t have a whole lot of experience myself, but I did fix another similar issue with Decimal earlier, so I would be happy to give any help that I can.

Sincerely,
Morten

Bug report: [SR-10938] abs(Decimal.nan) returns 0 · Issue #4001 · apple/swift-corelibs-foundation · GitHub

1 Like

Perfect! :slight_smile:
I’d like to give the solution a try - unless you’d like to give it a go yourself.

That will be great :slight_smile: