ballerina-lang icon indicating copy to clipboard operation
ballerina-lang copied to clipboard

Handle decimal subnormal and underflow cases

Open gabilang opened this issue 2 years ago • 3 comments

Purpose

This PR treats the decimal subnormal values as Zero according to IEEE-754 Decimal specification.

Fixes #38082

Approach

The absolute decimal values smaller than the minimum positive normal decimal value are treated as decimal value zero.

Samples

Remarks

Check List

  • [x] Read the Contributing Guide
  • [ ] Updated Change Log
  • [ ] Checked Tooling Support (#<Issue Number>)
  • [ ] Added necessary tests
    • [x] Unit Tests
    • [ ] Spec Conformance Tests
    • [ ] Integration Tests
    • [ ] Ballerina By Example Tests
  • [ ] Increased Test Coverage
  • [ ] Added necessary documentation
    • [ ] API documentation
    • [ ] Module documentation in Module.md files
    • [ ] Ballerina By Examples

gabilang avatar Oct 12 '22 05:10 gabilang

Codecov Report

Base: 76.70% // Head: 76.72% // Increases project coverage by +0.01% :tada:

Coverage data is based on head (1e02dce) compared to base (2c5023c). Patch coverage: 93.24% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #38172      +/-   ##
============================================
+ Coverage     76.70%   76.72%   +0.01%     
- Complexity    53056    53065       +9     
============================================
  Files          3356     3356              
  Lines        199240   199224      -16     
  Branches      25820    25817       -3     
============================================
+ Hits         152832   152850      +18     
+ Misses        37778    37745      -33     
+ Partials       8630     8629       -1     
Impacted Files Coverage Δ
.../org/ballerinalang/langlib/decimal/FromString.java 85.71% <ø> (-4.29%) :arrow_down:
...inalang/formatter/core/FormattingTreeModifier.java 95.83% <ø> (ø)
...testerina/natives/mock/GenericMockObjectValue.java 8.75% <ø> (ø)
...viders/context/ConstantDeclarationNodeContext.java 94.02% <50.00%> (ø)
.../providers/context/EnumDeclarationNodeContext.java 85.71% <50.00%> (ø)
...viders/context/ListenerDeclarationNodeContext.java 73.33% <50.00%> (ø)
...text/ModuleXMLNamespaceDeclarationNodeContext.java 89.18% <50.00%> (ø)
...eaction/providers/ExtractToLocalVarCodeAction.java 89.47% <80.00%> (ø)
...lerina/runtime/api/constants/RuntimeConstants.java 94.73% <100.00%> (ø)
...untime/internal/util/exceptions/RuntimeErrors.java 99.09% <100.00%> (+<0.01%) :arrow_up:
... and 39 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

codecov[bot] avatar Oct 12 '22 18:10 codecov[bot]

decimal d1 = 1.01e-6143d; Does this case a subnormal? With this change, the resut is 1.01E-6143, but for decimal d1 = 0.01e-6143d; it gives zero.

KavinduZoysa avatar Oct 17 '22 03:10 KavinduZoysa

decimal d1 = 1.01e-6143d; Does this case a subnormal? With this change, the resut is 1.01E-6143, but for decimal d1 = 0.01e-6143d; it gives zero.

Since the exponent of minimum representable magnitude of normal decimal value according to the spec is -6143, the value 0.01e-6143 is going to fall in subnormal range. So the value of 0.01e-6143d need to be treat as zero and 1.01e-6143d is a normal decimal value.

gabilang avatar Oct 17 '22 04:10 gabilang