You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Applying a numeric function (at least subtraction, possibly others) to numbers large enough to overflow an int will fail. The following code should output 10.0 but actually outputs 0.0.
import ca.uqac.lif.cep.util.Numbers;
import ca.uqac.lif.cep.functions.Function;
public class TestDiff {
public static void main(String[] args) {
Function negation = Numbers.subtraction;
Object[] out = new Object[1];
negation.evaluate(new Object[]{1590785415514L, 1590785415504L}, out);
System.out.println("The return value of the function is: " + out[0]);
}
}
The text was updated successfully, but these errors were encountered:
Sadly, Java does not allow operations directly on instances of Number, so a conversion to some concrete type must be done. I chose float out of a (sparsely justified) belief that operations on floats are faster than on doubles. A possible solution would be simply to switch all functions in the Number class to doubles internally.
Is there a specific use case that requires you to use such large numbers?
The use case is to calculate the difference between millisecond-granularity timestamps, such as those returned by System.currentTimeMillis(). In my case, there is a workaround, because I know that the timestamps in question will fall within a certain period. So, I can just mask off everything except the lower several bits. However, I could foresee circumstances where this isn't possible.
If there was a warning that told the user they lost information from the cast, that might be a helpful solution.
Applying a numeric function (at least subtraction, possibly others) to numbers large enough to overflow an int will fail. The following code should output 10.0 but actually outputs 0.0.
The text was updated successfully, but these errors were encountered: