Index: src/math.c ================================================================== --- src/math.c +++ src/math.c @@ -132,11 +132,11 @@ xHi = x>>32; yHi = y>>32; if( xHi*yHi ) return 1; xLo = x & 0xffffffff; yLo = y & 0xffffffff; - if( (xHi*yLo + yHi*xLo)>0xffffffff ) return 1; + if( (xHi*yLo + yHi*xLo + (xLo*yLo>>32))>0xffffffff ) return 1; return 0; } /* ** Multiply two numbers and return the result. Index: test/num.test ================================================================== --- test/num.test +++ test/num.test @@ -97,10 +97,18 @@ } { 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 { + sqlite4_num_mul 3 6148914690091192593 +} {sign:0 approx:0 e:0 m:18446744070273577779} do_test num-6.1.1 { sqlite4_num_to_text [sqlite4_num_div 6 5] } {1.2} do_test num-6.1.2 {