/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/common/fast_number.vala

  • Committer: Gustav Hartvigsson
  • Date: 2021-09-09 15:13:25 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210909151325-4ck5ldym2pgyk7yz
* fixed the parsing of string in FastNumber.parse_raw_number ()

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
      public set {set_decimal_of_number (ref raw_number, value);}
35
35
    }
36
36
    
 
37
    public double float_rep {
 
38
      public get {return double.parse (@"$number" + "." + @"$decimal");}
 
39
      public set {this.raw_number = parse_raw_number (value.to_string ());}
 
40
    }
 
41
    
37
42
    public FastNumber (long val = 0) {
38
43
      this.number = val;
39
44
    }
46
51
      this.raw_number = parse_raw_number (str);
47
52
    }
48
53
    
 
54
    public FastNumber.from_float (double f) {
 
55
      this.raw_number = parse_raw_number (f.to_string ());
 
56
    }
 
57
    
49
58
    public FastNumber.raw (long raw) {
50
59
      this.raw_number = raw;
51
60
    }
135
144
      long ret_val = 0;
136
145
      int i_of_dot = str.index_of_char ('.');
137
146
      if (i_of_dot >= 0) {
138
 
      
 
147
        
 
148
        debug (@"str: $str");
 
149
        
139
150
        // Get the decimal number from the string, if such a thing exists.
140
151
        if ((str.length - 1 > i_of_dot)) {
141
152
          ret_val = long.parse ((str + "000").substring (i_of_dot + 1));
142
153
        }
143
154
        
 
155
        debug (@"i_of_dot: $i_of_dot, ret_val (decimal): $ret_val\n");
 
156
        
144
157
        // Normalise the digits.
145
158
        while (ret_val > MUL_FACTOR) {
146
159
          ret_val = ret_val / 10;
147
160
        }
148
161
        
 
162
        debug (@"ret_val (normalised): $ret_val\n");
 
163
        
149
164
        // Add intiger number
150
 
        ret_val = ret_val + (long.parse ("0" + str.substring (0, i_of_dot))
 
165
        ret_val = ret_val + (long.parse (str.substring (0, i_of_dot))
151
166
                            * MUL_FACTOR);
 
167
        
 
168
        debug (@"ret_val (finised): $ret_val\n");
 
169
        
152
170
      } else {
153
171
        ret_val = long.parse (str) * MUL_FACTOR;
154
172
      }