/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk
1 by Gustav Hartvigsson
* Initial code - far from done
1
namespace VQDR.Expression {
2
  
3
  class DivideOperatorToken : OperatorToken {
4
    
5
    construct {
6
      mandatory_num_child = 2;
14 by Gustav Hartvigsson
* Use enum instead of static values for the priority of operations.
7
      priority = Prio.MULTIPLICATIVE;
1 by Gustav Hartvigsson
* Initial code - far from done
8
    }
9
    
11 by Gustav Hartvigsson
* FastNumber:
10
    public DivideOperatorToken (int position) {
1 by Gustav Hartvigsson
* Initial code - far from done
11
      base (position);
12
    }
13
    
14
    public override void evaluate_self (Context instance) throws GLib.Error {
15
      Token r_child = get_right_child (),
16
            l_child = get_left_child ();
17
             
18
      l_child.evaluate (instance);
19
      r_child.evaluate (instance);
20
      
21
      // Division by zero is not somthing we want to do.
22
      // Black holes are bad.
12.1.1 by Gustav Hartvigsson
* Switch to using FastNumber instead of something else.
23
      if (l_child.result_value.number == 0) {
1 by Gustav Hartvigsson
* Initial code - far from done
24
        throw new VQDR.Common.MathError.DIVIDE_BY_ZERO
25
        ("(DivideOperationToken) The left value is less than zero.");
26
      }
27
      
28
      var sb = new GLib.StringBuilder ("(");
29
      
30
      // We check the precidence of the token, and inclose the value if
31
      // it has a lower precidence than multiply, if it is, we enclose it in a
32
      // praranthesis.
33
      if (l_child.priority > 0 && l_child.priority < priority) {
34
        sb.append ("(").append (l_child.result_string).append (")");
35
        //l_child.result_string = "(" + l_child.result_string + ")";
36
      } else {
37
        sb.append (l_child.result_string);
38
      }
39
      
40
      sb.append ("*");
41
      
42
      // We do the same with the othre child.
43
      if (r_child.priority > 0 && r_child.priority < priority) {
44
        sb.append ("(").append (r_child.result_string).append (")");
45
        //r_child.result_string = "(" + r_child.result_string + ")";
46
      } else {
47
        sb.append (r_child.result_string);
48
      }
49
      
50
      sb.append (")");
51
      
12.1.1 by Gustav Hartvigsson
* Switch to using FastNumber instead of something else.
52
      result_value = l_child.result_value.divide (l_child.result_value);
53
      result_max_value = l_child.result_max_value.divide (l_child.result_max_value);
1 by Gustav Hartvigsson
* Initial code - far from done
54
      reorder_max_min_values ();
55
      result_string = sb.str;
56
       
57
    }
58
    
59
  }
60
  
61
  
62
}