Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions Sources/CSQLite/csqlite_shims.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,6 @@ int csqlite_sqlite3_db_config_enable_comments(sqlite3 *db, int x, int *y)
return sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_COMMENTS, x, y);
}

int csqlite_sqlite3_db_config_fp_digits(sqlite3 *db, int x, int *y)
{
return sqlite3_db_config(db, SQLITE_DBCONFIG_FP_DIGITS, x, y);
}

// MARK: - Virtual table configuration

int csqlite_sqlite3_vtab_config_constraint_support(sqlite3 *db, int x)
Expand Down
43 changes: 5 additions & 38 deletions Sources/CSQLite/decimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,36 +291,12 @@ static void decimal_result(sqlite3_context *pCtx, Decimal *p){
sqlite3_result_text(pCtx, z, i, sqlite3_free);
}

/*
** Round a decimal value to N significant digits. N must be positive.
*/
static void decimal_round(Decimal *p, int N){
int i;
int nZero;
if( N<1 ) return;
for(nZero=0; nZero<p->nDigit && p->a[nZero]==0; nZero++){}
N += nZero;
if( p->nDigit<=N ) return;
if( p->a[N]>4 ){
p->a[N-1]++;
for(i=N-1; i>0 && p->a[i]>9; i--){
p->a[i] = 0;
p->a[i-1]++;
}
if( p->a[0]>9 ){
p->a[0] = 1;
p->nFrac--;
}
}
memset(&p->a[N], 0, p->nDigit - N);
}

/*
** Make the given Decimal the result in an format similar to '%+#e'.
** In other words, show exponential notation with leading and trailing
** zeros omitted.
*/
static void decimal_result_sci(sqlite3_context *pCtx, Decimal *p, int N){
static void decimal_result_sci(sqlite3_context *pCtx, Decimal *p){
char *z; /* The output buffer */
int i; /* Loop counter */
int nZero; /* Number of leading zeros */
Expand All @@ -338,8 +314,7 @@ static void decimal_result_sci(sqlite3_context *pCtx, Decimal *p, int N){
sqlite3_result_null(pCtx);
return;
}
if( N<1 ) N = 0;
for(nDigit=p->nDigit; nDigit>N && p->a[nDigit-1]==0; nDigit--){}
for(nDigit=p->nDigit; nDigit>0 && p->a[nDigit-1]==0; nDigit--){}
for(nZero=0; nZero<nDigit && p->a[nZero]==0; nZero++){}
nFrac = p->nFrac + (nDigit - p->nDigit);
nDigit -= nZero;
Expand Down Expand Up @@ -702,16 +677,10 @@ static void decimalFunc(
sqlite3_value **argv
){
Decimal *p = decimal_new(context, argv[0], 0);
int N;
if( argc==2 ){
N = sqlite3_value_int(argv[1]);
if( N>0 ) decimal_round(p, N);
}else{
N = 0;
}
UNUSED_PARAMETER(argc);
if( p ){
if( sqlite3_user_data(context)!=0 ){
decimal_result_sci(context, p, N);
decimal_result_sci(context, p);
}else{
decimal_result(context, p);
}
Expand Down Expand Up @@ -881,7 +850,7 @@ static void decimalPow2Func(
UNUSED_PARAMETER(argc);
if( sqlite3_value_type(argv[0])==SQLITE_INTEGER ){
Decimal *pA = decimalPow2(sqlite3_value_int(argv[0]));
decimal_result_sci(context, pA, 0);
decimal_result_sci(context, pA);
decimal_free(pA);
}
}
Expand All @@ -902,9 +871,7 @@ int sqlite3_decimal_init(
void (*xFunc)(sqlite3_context*,int,sqlite3_value**);
} aFunc[] = {
{ "decimal", 1, 0, decimalFunc },
{ "decimal", 2, 0, decimalFunc },
{ "decimal_exp", 1, 1, decimalFunc },
{ "decimal_exp", 2, 1, decimalFunc },
{ "decimal_cmp", 2, 0, decimalCmpFunc },
Comment on lines 871 to 875
{ "decimal_add", 2, 0, decimalAddFunc },
{ "decimal_sub", 2, 0, decimalSubFunc },
Expand Down
36 changes: 1 addition & 35 deletions Sources/CSQLite/ieee754.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ static void ieee754func(
}

if( m<0 ){
if( m<(-9223372036854775807LL) ) return;
isNeg = 1;
m = -m;
if( m<0 ) return;
Comment on lines 182 to +184
}else if( m==0 && e>-1000 && e<1000 ){
sqlite3_result_double(context, 0.0);
return;
Expand Down Expand Up @@ -259,38 +259,6 @@ static void ieee754func_to_blob(
}
}

/*
** Functions to convert between 64-bit integers and floats.
**
** The bit patterns are copied. The numeric values are different.
*/
static void ieee754func_from_int(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
UNUSED_PARAMETER(argc);
if( sqlite3_value_type(argv[0])==SQLITE_INTEGER ){
double r;
sqlite3_int64 v = sqlite3_value_int64(argv[0]);
memcpy(&r, &v, sizeof(r));
sqlite3_result_double(context, r);
}
}
static void ieee754func_to_int(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
UNUSED_PARAMETER(argc);
if( sqlite3_value_type(argv[0])==SQLITE_FLOAT ){
double r = sqlite3_value_double(argv[0]);
sqlite3_uint64 v;
memcpy(&v, &r, sizeof(v));
sqlite3_result_int64(context, v);
}
}

/*
** SQL Function: ieee754_inc(r,N)
**
Expand Down Expand Up @@ -343,8 +311,6 @@ int sqlite3_ieee_init(
{ "ieee754_exponent", 1, 2, ieee754func },
{ "ieee754_to_blob", 1, 0, ieee754func_to_blob },
{ "ieee754_from_blob", 1, 0, ieee754func_from_blob },
{ "ieee754_to_int", 1, 0, ieee754func_to_int },
{ "ieee754_from_int", 1, 0, ieee754func_from_int },
{ "ieee754_inc", 2, 0, ieee754inc },
};
unsigned int i;
Expand Down
2 changes: 0 additions & 2 deletions Sources/CSQLite/include/csqlite_shims.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ int csqlite_sqlite3_db_config_enable_attach_create(sqlite3 *db, int x, int *y);
int csqlite_sqlite3_db_config_enable_attach_write(sqlite3 *db, int x, int *y);
/// Equivalent to `sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_COMMENTS, x, y)`
int csqlite_sqlite3_db_config_enable_comments(sqlite3 *db, int x, int *y);
/// Equivalent to `sqlite3_db_config(db, SQLITE_DBCONFIG_FP_DIGITS, x, y)`
int csqlite_sqlite3_db_config_fp_digits(sqlite3 *db, int x, int *y);

// MARK: - Virtual table configuration
// See https://sqlite.org/c3ref/vtab_config.html
Expand Down
Loading
Loading