Skip to content

Commit

Permalink
Wollok very big integer support (using decimals)
Browse files Browse the repository at this point in the history
  • Loading branch information
fdodino committed Oct 20, 2016
1 parent b223d58 commit 9afd7c1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -425,4 +425,28 @@ class NumberTestCase extends AbstractWollokInterpreterTestCase {
'''.test
}

@Test
def void veryBigIntegerAdd() {
'''
var a = 100000000000000000
assert.equals(100000000000000001, a + 1)
'''.test
}

@Test
def void veryBigIntegerMultiply() {
'''
var a = 100000000000000000
assert.equals(100000000000000000, a * 1)
'''.test
}

@Test
def void veryBigIntegerDivide() {
'''
var a = 100000000000000000
assert.equals(100000, a / 1000000000000)
'''.test
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,12 @@ class WollokInterpreterEvaluator implements XInterpreterEvaluator<WollokObject>
if (value.contains('.'))
doInstantiateNumber(DOUBLE, new BigDecimal(value))
else {
doInstantiateNumber(INTEGER, Integer.valueOf(value))
try {
doInstantiateNumber(INTEGER, Integer.valueOf(value))
} catch (NumberFormatException e) {
// If value is too long, use a decimal
doInstantiateNumber(DOUBLE, new BigDecimal(value))
}
}
}

Expand Down

0 comments on commit 9afd7c1

Please sign in to comment.