Guest User

Untitled

a guest
Feb 18th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. open Num
  2. open Big_int
  3. open Ratio
  4. open Printf
  5.  
  6. let divide a b =
  7. let q = quo_num a b in
  8. let r = mod_num a b in
  9. sprintf "q=%-2s r=%-2s" (string_of_num q) (string_of_num r)
  10. ;;
  11.  
  12. let testall a b =
  13. let i x = Int x in
  14. let bi x = Big_int (big_int_of_int x) in
  15. let r x = Ratio (ratio_of_int x) in
  16. printf "/---------------------------------------------\\\n";
  17. printf "| %2d/%2d | Int | Big_int | Ratio |\n" a b;
  18. printf "|---------------------------------------------|\n";
  19. printf "| Int | %s | %s | %s |\n"
  20. (divide (i a) (i b))
  21. (divide (i a) (bi b))
  22. (divide (i a) (r b));
  23. printf "|---------------------------------------------|\n";
  24. printf "| Big_int | %s | %s | %s |\n"
  25. (divide (bi a) (i b))
  26. (divide (bi a) (bi b))
  27. (divide (bi a) (r b));
  28. printf "|---------------------------------------------|\n";
  29. printf "| Ratio | %s | %s | %s |\n"
  30. (divide (r a) (i b))
  31. (divide (r a) (bi b))
  32. (divide (r a) (r b));
  33. printf "\\---------------------------------------------/\n";
  34. ;;
  35.  
  36. let sep () = printf "\n";;
  37.  
  38. testall 5 3;;
  39. sep ();;
  40. testall (-5) 3;;
  41. sep ();;
  42. testall 5 (-3);;
  43. sep ();;
  44. testall (-5) (-3);;
Add Comment
Please, Sign In to add comment