/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk

« back to all changes in this revision

Viewing changes to src/libvqdr/token.vala

  • Committer: Gustav Hartvigsson
  • Date: 2021-09-08 21:15:31 UTC
  • mfrom: (12.1.3 fastnumber)
  • Revision ID: gustav.hartvigsson@gmail.com-20210908211531-xyhqodfa2gmzxurl
* merge the FastNumber branch. this will make code reuse better.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
namespace VQDR.Expression {
5
5
  
6
6
  public abstract class Token : GLib.Object {
7
 
    /** Precision used to perform evaluation */
8
 
    public const int VALUES_PRECISION_DIGITS = 3;
9
 
    /** Precision factor used to convert raw values to actual ones */
10
 
    public const int VALUES_PRECISION_FACTOR = 1000;
11
 
    //public static int VALUES_PRECISION_FACTOR = (int)Math.pow(10, VALUES_PRECISION_DIGITS);
12
 
    
13
7
    /** Precision used to output values */
14
8
    public const int VALUES_OUTPUT_PRECISION_DIGITS = 2;
15
9
    /** Precision factor used to evaluate output */
141
135
    /** all children of this token */
142
136
    private (unowned Token?)[] children;
143
137
    
144
 
    
145
 
    public long result_value {public get; protected set; default = 0;}
146
 
    public long result_max_value {public get; protected set; default = 0;}
147
 
    public long result_min_value {public get; protected set; default = 0;}
 
138
    /*
 
139
     * These values should have a protected setter, but I could not get it to
 
140
     * work. So we will have to live with this.
 
141
     */
 
142
    public FastNumber result_value;
 
143
    public FastNumber result_max_value;
 
144
    public FastNumber result_min_value;
148
145
    public string result_string {public get; protected set; default = "";}
149
146
    
150
147
    construct {
151
 
      // Valgrind says there is a memory leak here... But it's actually
152
 
      // GObject's constructor that is leaking.
153
148
      children = new Token[max_num_child];
154
149
      next_child = 0;
 
150
      
 
151
      result_value = FastNumber ();
 
152
      result_max_value = FastNumber ();
 
153
      result_min_value = FastNumber ();
155
154
    }
156
155
    
157
156
    
165
164
     * result_min_value is the smaller.
166
165
     */
167
166
    protected void reorder_max_min_values () {
168
 
      if (result_max_value < result_min_value) {
169
 
        long tmp = result_max_value;
 
167
      if (result_max_value.compare (result_min_value) <= 0) {
 
168
        FastNumber tmp = result_max_value;
170
169
        result_max_value = result_min_value;
171
170
        result_min_value = tmp;
172
171
      }