ballerina-platform / ballerina-spec

Ballerina Language and Platform Specifications
Other
168 stars 53 forks source link

Decimal subnormals should be treated as zero #995

Open jclark opened 2 years ago

jclark commented 2 years ago

The spec says https://ballerina.io/spec/lang/2021R1/#section_5.2.4.2

The decimal type corresponds to the ANSI X3.274 subset of IEEE 754-2008

but also

NaN, infinities and subnormals are not supported; operations that would result in one of these values according to the normal rules of IEEE 754-2008 instead result in a panic [my emphasis]

The second part is correct for NaN and infinities, but incorrect for subnormals: a subnormal value should be treated as zero according to X3.274 rather than an error. (Subnormals are values with very small magnitude, which serve to make underflow gradual.)

jclark commented 2 years ago

See also this discussion: https://github.com/ballerina-platform/nballerina/pull/699#discussion_r751916077

@gimantha Please have a look at this.

gabilang commented 2 years ago

Since subnormals are treated as zero, what would be the result of === operator with decimal subnormal results and decimal zero values? Should we consider precision for the decimal value Zero (theoretically decimal zero is less than the minimum decimal magnitude)?