Guest User

Untitled

a guest
Jan 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. public Rational ceiling()
  2. {
  3. int num;
  4. int denom;
  5. float high = 0;
  6. float a = ((float) getNumerator()/(float) getDenominator());
  7. if(a > 0)
  8. {
  9. high = new Float(a + (1-(a % 1)));
  10. }
  11. if(a < 0)
  12. {
  13. high = new Float(a + (a % 1));
  14. }
  15. denom = 1;
  16. num = (int) high;
  17. Rational cei = new Rational(num,denom);
  18. return cei;
  19. }
  20.  
  21.  
  22. public Rational floor()
  23. {
  24. int num;
  25. int denom;
  26. float low = 0;
  27. float a = ((float) getNumerator()/(float) getDenominator());
  28. if(a > 0)
  29. {
  30. low = new Float(a - (a % 1));
  31. }
  32. if(a < 0)
  33. {
  34. low = new Float(a - (1 - (a % 1)));
  35. }
  36. denom = 1;
  37. num = (int) low;
  38. Rational flo = new Rational(num,denom);
  39. return flo;
  40. }
Add Comment
Please, Sign In to add comment