ericmj / decimal

Arbitrary precision decimal arithmetic

Home Page:https://hexdocs.pm/decimal/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Decimal.negate(0) should return #Decimal<0> rather than #Decimal<-0>

agrits opened this issue · comments

Like in the title:

iex> Decimal.negate(0)
#Decimal<-0>

Is this behaviour specified anywhere, e.g. IEEE 754/854?

It specifies two signed zeros in existence.
Then, I guess this is also correct:

iex> Decimal.to_string(Decimal.negate(0))
"-0"

and the issue is not needed.

Treating the integer 0 as decimal +0 makes sense to me and then it follows that Decimal.negate(+0) => -0.

If you see it differently please elaborate on why.

It specifies two signed zeros in existence.

Yes, that exists in IEEE 754.