How to calculate the rest of division on very large number in KNIME?
.
Indeed, inside the “Math Formula” node, the mod(x,y) or x%y function is limited to " 2147483647".
To avoid this limitation it’s possible to use the folowing process like (in VBA)
Function RestePar97(Nbre As String) As Integer
Dim i As Integer
RestePar97 = 0
For i = 0 To Len(Nbre) - 1
RestePar97 = (RestePar97 * 10 + CInt(Mid(Nbre, i + 1, 1))) Mod 97
Next i
End Function
maybe i misunderstand your question - why not just use the long format in KNIME?
Else you could use the java snippet node (or python nodes) to accomplish the same - but I think using long is easier to use (the limit here should be 9223372036854775807)
If you want mod for even larger calculations I would suggest to use java/python functions for large numbers e.g. bigint mod
Hi @PBJ , the Math Formula is able to go beyond that. 2147483647 is basically the max value of a signed int (the range is -2,147,483,648 to 2,147,483,647). If you use type Long as @AnotherFraudUser pointed out, it will go beyond that number.
it seems you are correct -it looks like there is a problem with incorrect casting there
Attached a java snippet with multiple ways to do the mod with the Java Snippet.
I think using these pre-build java function would be the correct way - or do you really want to build you self made function within knime?
This issue seems to happen after a certain range/limit. I originally tested with some Long numbers, and they all passed, and I was about to reply that I did not have any issue on my side because of that, then I thought of testing with the numbers that @PBJ used, and unfortunately I got the same results too.
Some test results:
Adding the number 1 at the beginning as an additional digit:
Then I used the Math Formula (Multi Column) to go faster. At first, I did 4 columns in total (including the 2 above). Then I added @PBJ test data in column5. The first 4 columns produced the correct results, but for column5, it produced the same results as @PBJ:
I’m guessing it’s the same mod() function in the Math Formula and the Column Expression.
But the issue might not be with the mod() function, but rather how these numbers are being recognized. Here’s an additional test that I did. I did column4 / 10 and also column5 / 10. Here are the results: