/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-05-24 16:34:03 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210524163403-jisvydo4nj9vdses
* removed test code from main.vala

* use real_raw_value in Fastnumber

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
   * Math done on these numbers are done using standard integer operations, and
9
9
   * not floating point math.
10
10
   */
11
 
  
12
11
  public class FastNumber {
13
12
    public const long MUL_FACTOR = 1000;
14
13
    
15
 
    private long real_raw_number;
 
14
    protected long real_raw_number;
16
15
    public long raw_number { public get {return real_raw_number;}
17
16
                             private set {real_raw_number = value;}
18
17
    }
32
31
    }
33
32
    
34
33
    public FastNumber.copy (FastNumber other) {
35
 
      this.raw_number = other.raw_number;
 
34
      this.real_raw_number = other.real_raw_number;
36
35
    }
37
36
    
38
37
    public FastNumber.from_string (string str) {
39
 
      this.raw_number = parse_raw_number (str);
 
38
      this.real_raw_number = parse_raw_number (str);
40
39
    }
41
40
    
42
41
    private static long parse_raw_number (string str) {
70
69
      }
71
70
      
72
71
      var v = new FastNumber ();
73
 
      v.raw_number = (this.raw_number + other.raw_number);
 
72
      v.raw_number = (this.real_raw_number + other.real_raw_number);
74
73
      return v;
75
74
    }
76
75
    
80
79
      }
81
80
      
82
81
      var v = new FastNumber ();
83
 
      v.raw_number = (this.raw_number - other.raw_number);
 
82
      v.raw_number = (this.real_raw_number - other.real_raw_number);
84
83
      return v;
85
84
    }
86
85
    
87
86
    public FastNumber multiply (FastNumber? other) {
88
 
      if (other == null || other.raw_number == 0) {
 
87
      if (other == null || other.real_raw_number == 0) {
89
88
        return new FastNumber ();
90
89
      }
91
90
      
92
91
      var ret = new FastNumber ();
93
 
      ret.raw_number = ((this.raw_number * other.raw_number) / MUL_FACTOR);
 
92
      ret.raw_number = ((this.real_raw_number * other.real_raw_number) / MUL_FACTOR);
94
93
      return ret;
95
94
    }
96
95
    
97
96
    public FastNumber divide (FastNumber? other) throws MathError {
98
 
      if (other.raw_number == 0) {
 
97
      if (other.real_raw_number == 0) {
99
98
        throw new MathError.DIVIDE_BY_ZERO
100
99
                                      ("FantNumber - trying to divide by zero");
101
100
      }
102
101
      var ret = new FastNumber ();
103
 
      ret.raw_number = ((this.raw_number * MUL_FACTOR) / other.raw_number);
 
102
      ret.raw_number = ((this.real_raw_number * MUL_FACTOR) / other.real_raw_number);
104
103
      return ret;
105
104
    }
106
105
    
115
114
      masked = masked * MUL_FACTOR;
116
115
      number = masked + decimal;
117
116
    }
118
 
    
119
117
  }
120
 
  
121
118
}