Guest User

Untitled

a guest
Jul 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. public static double[] toArray(Sequence s, int from, int to) throws UndefinedElementException {
  2.  
  3. double[] outputArray = new double[(to - from)];
  4. int position = from;
  5. double makeIntTemp1;
  6. int makeIntTemp2;
  7. for (int i = 0; i < (to - from); i++) {//invariant: from <= i <= (to-from)
  8. try {
  9. //round to 2 decimal places
  10. makeIntTemp1 = s.getElementAtIndex(position) * 100;
  11. makeIntTemp2 = (int) makeIntTemp1;
  12. outputArray[i] = (double) (makeIntTemp2 / 100.0);
  13.  
  14. //outputArray[i] = s.getElementAtIndex(position); //test without rounding
  15.  
  16. position++;
  17. } catch (UndefinedElementException e) {
  18. outputArray[i] = Double.NaN;
  19. }
  20. }
  21. return outputArray;
  22. }
Add Comment
Please, Sign In to add comment