SQLite4
Check-in [b667dab56b]
Not logged in

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

Overview
Comment:Coverting an approximate sqlite4_num to int64 is flagged as lossy.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b667dab56bc22b929414a958d645a1b21e2bd2a4
User & Date: peterreid 2013-06-07 00:49:46
Context
2013-06-07
00:51
Correct comments in header of num test check-in: 8cb787fa4a user: peterreid tags: trunk
00:49
Coverting an approximate sqlite4_num to int64 is flagged as lossy. check-in: b667dab56b user: peterreid tags: trunk
2013-06-06
17:18
Change the names of some API functions to make their purposes clearer: "get_auxdata" -> "auxdata_fetch", "set_auxdata" -> "auxdata_store", "get_autocommit" -> "db_transaction_status", and "sql" -> "stmt_sql". check-in: c8d956ad1a user: dan tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/math.c.

537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
*/
sqlite4_int64 sqlite4_num_to_int64(sqlite4_num num, int *pbLossy){
  static const i64 L10 = (LARGEST_INT64 / 10);
  u64 iRet;
  int i;
  iRet = num.m;

  if( pbLossy ) *pbLossy = 0;
  for(i=0; i<num.e; i++){
    if( iRet>L10 ) goto overflow;
    iRet = iRet * 10;
  }
  for(i=num.e; i<0; i++){
    if( pbLossy && (iRet % 10) ) *pbLossy = 1;
    iRet = iRet / 10;







|







537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
*/
sqlite4_int64 sqlite4_num_to_int64(sqlite4_num num, int *pbLossy){
  static const i64 L10 = (LARGEST_INT64 / 10);
  u64 iRet;
  int i;
  iRet = num.m;

  if( pbLossy ) *pbLossy = num.approx;
  for(i=0; i<num.e; i++){
    if( iRet>L10 ) goto overflow;
    iRet = iRet * 10;
  }
  for(i=num.e; i<0; i++){
    if( pbLossy && (iRet % 10) ) *pbLossy = 1;
    iRet = iRet / 10;

Changes to test/num.test.

174
175
176
177
178
179
180

181
182
183
184
185
186
187
188
189
  10    {sign:0 approx:0 e:50 m:244}                 ~9223372036854775807
  11    {sign:1 approx:0 e:50 m:34220}               ~-9223372036854775808
  12    50.1                                         ~50
  13    10.9                                         ~10
  14    .995                                         ~0
  15    -93.9                                        ~-93
  16    -12.1                                        ~-12

} {
  do_test num-10.1.$tn { sqlite4_num_to_int64 $in } [list {*}$out]
}


#-------------------------------------------------------------------------
finish_test









>









174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
  10    {sign:0 approx:0 e:50 m:244}                 ~9223372036854775807
  11    {sign:1 approx:0 e:50 m:34220}               ~-9223372036854775808
  12    50.1                                         ~50
  13    10.9                                         ~10
  14    .995                                         ~0
  15    -93.9                                        ~-93
  16    -12.1                                        ~-12
  17    {sign:0 approx:1 e:0 m:4053}                 ~4053
} {
  do_test num-10.1.$tn { sqlite4_num_to_int64 $in } [list {*}$out]
}


#-------------------------------------------------------------------------
finish_test