Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static double[] toArray(Sequence s, int from, int to) throws UndefinedElementException {
- double[] outputArray = new double[(to - from)];
- int position = from;
- double makeIntTemp1;
- int makeIntTemp2;
- for (int i = 0; i < (to - from); i++) {//invariant: from <= i <= (to-from)
- try {
- //round to 2 decimal places
- makeIntTemp1 = s.getElementAtIndex(position) * 100;
- makeIntTemp2 = (int) makeIntTemp1;
- outputArray[i] = (double) (makeIntTemp2 / 100.0);
- //outputArray[i] = s.getElementAtIndex(position); //test without rounding
- position++;
- } catch (UndefinedElementException e) {
- outputArray[i] = Double.NaN;
- }
- }
- return outputArray;
- }
Add Comment
Please, Sign In to add comment