Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Prevent unnecessary rounding before multiplying
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 68dfaa349103e9111e7a53e26ebe3d0743bf8178
User & Date: peterreid 2013-10-23 22:54:23.681
Context
2013-10-24
19:59
Updates to code to read log files. check-in: aabb6dacf6 user: dan tags: trunk
2013-10-23
22:54
Prevent unnecessary rounding before multiplying check-in: 68dfaa3491 user: peterreid tags: trunk
22:43
Fix undetected multiplication overflow check-in: 2eba06d522 user: peterreid tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/math.c.
151
152
153
154
155
156
157


158
159
160
161
162
163
164
    r.approx = 0;
    return r;
  }
  if( A.m==0 ) return A;
  if( B.m==0 ) return B;
  while( A.m%10==0 ){ A.m /= 10; A.e++; }
  while( B.m%10==0 ){ B.m /= 10; B.e++; }


  r.sign = A.sign ^ B.sign;
  r.approx = A.approx | B.approx;
  while( multWillOverflow(A.m, B.m) ){
    r.approx = 1;
    if( A.m>B.m ){
      A.m /= 10;
      A.e++;







>
>







151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
    r.approx = 0;
    return r;
  }
  if( A.m==0 ) return A;
  if( B.m==0 ) return B;
  while( A.m%10==0 ){ A.m /= 10; A.e++; }
  while( B.m%10==0 ){ B.m /= 10; B.e++; }
  while( A.m%5==0 && B.m%2==0 ){ A.m /= 5; A.e++; B.m /= 2; }
  while( B.m%5==0 && A.m%2==0 ){ B.m /= 5; B.e++; A.m /= 2; }
  r.sign = A.sign ^ B.sign;
  r.approx = A.approx | B.approx;
  while( multWillOverflow(A.m, B.m) ){
    r.approx = 1;
    if( A.m>B.m ){
      A.m /= 10;
      A.e++;
Changes to test/num.test.
94
95
96
97
98
99
100









101
102
103
104
105
106
107
  7   NaN     1       NaN
  8   NaN     -9      NaN
  9   NaN     NaN     NaN
} { 
  do_test num-5.1.$tn {
    sqlite4_num_to_text [sqlite4_num_mul $a $b]
  } $product









}
# 5.2: Overflow that depends on the product of the two least 
# significant halves
do_test num-5.2.1 {
  sqlite4_num_mul 3 6148914691236517211
} {sign:0 approx:1 e:1 m:1844674407370955163}
do_test num-5.2.2 {







>
>
>
>
>
>
>
>
>







94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
  7   NaN     1       NaN
  8   NaN     -9      NaN
  9   NaN     NaN     NaN
} { 
  do_test num-5.1.$tn {
    sqlite4_num_to_text [sqlite4_num_mul $a $b]
  } $product
}
foreach {tn a b product} {
  1 1125899906842624 95367431640625   107374182400000000000000000000
  1 95367431640625   1125899906842624 107374182400000000000000000000
  2 40000000000      30000000000      1200000000000000000000
} { 
  do_test num-5.2.$tn {
    sqlite4_num_compare [sqlite4_num_mul $a $b] $product
  } {equal}
}
# 5.2: Overflow that depends on the product of the two least 
# significant halves
do_test num-5.2.1 {
  sqlite4_num_mul 3 6148914691236517211
} {sign:0 approx:1 e:1 m:1844674407370955163}
do_test num-5.2.2 {