Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1.  
  2. public class RealScalar extends Scalar {
  3. private double _value;
  4.  
  5. public RealScalar(double value)
  6. {
  7. _value = value; // should round it
  8. }
  9. public Scalar add(Scalar s) {
  10. RealScalar ans = new RealScalar(((RealScalar)s).getValue() + _value);
  11. return ans;
  12. }
  13.  
  14. public Scalar mul(Scalar s) {
  15. RealScalar ans = new RealScalar(((RealScalar)s).getValue() * _value);
  16. return ans;
  17. }
  18.  
  19. public Scalar neg() {
  20. RealScalar ans = new RealScalar(_value * -1);
  21. return ans;
  22. }
  23.  
  24. public Scalar inv() {
  25. RealScalar ans = new RealScalar(1/_value);
  26. return ans;
  27. }
  28.  
  29.  
  30. public boolean equals(Scalar s) {
  31. boolean ans = (((RealScalar)s).getValue() == _value);
  32. return ans;
  33. }
  34.  
  35. public double getValue()
  36. {
  37. return _value;
  38. }
  39.  
  40. public void setValue(double value)
  41. {
  42. _value = value;
  43. }
  44.  
  45. public String toString()
  46. {
  47. String ans = ""+_value;
  48. return ans;
  49. }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement