mirror of
https://github.com/sqlite/sqlite.git
synced 2025-10-21 11:13:54 +03:00
Increase strictness of the new experimental functions and add more tests.
FossilOrigin-Name: 05c4463ec5f36dde50f6eb116624dc40142f2c8c
This commit is contained in:
29
src/func.c
29
src/func.c
@@ -19,6 +19,9 @@
|
||||
#include "sqliteInt.h"
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#ifndef SQLITE_OMIT_FLOATING_POINT
|
||||
# include <math.h>
|
||||
#endif
|
||||
#include "vdbeInt.h"
|
||||
|
||||
/*
|
||||
@@ -986,6 +989,19 @@ static void tointegerFunc(
|
||||
UNUSED_PARAMETER(argc);
|
||||
switch( sqlite3_value_type(argv[0]) ){
|
||||
case SQLITE_FLOAT:
|
||||
#ifndef SQLITE_OMIT_FLOATING_POINT
|
||||
{
|
||||
double rVal = sqlite3_value_double(argv[0]);
|
||||
double rIntVal = 0.0;
|
||||
if( !sqlite3IsNaN(rVal) && modf(rVal, &rIntVal)==0.0 &&
|
||||
rIntVal>=SMALLEST_INT64 && rIntVal<=LARGEST_INT64 ){
|
||||
sqlite3_result_int64(context, (i64)rIntVal);
|
||||
return;
|
||||
}
|
||||
sqlite3_result_null(context);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
case SQLITE_INTEGER: {
|
||||
sqlite3_result_int64(context, sqlite3_value_int64(argv[0]));
|
||||
break;
|
||||
@@ -1038,11 +1054,20 @@ static void todoubleFunc(
|
||||
assert( argc==1 );
|
||||
UNUSED_PARAMETER(argc);
|
||||
switch( sqlite3_value_type(argv[0]) ){
|
||||
case SQLITE_FLOAT:
|
||||
case SQLITE_INTEGER: {
|
||||
case SQLITE_FLOAT: {
|
||||
sqlite3_result_double(context, sqlite3_value_double(argv[0]));
|
||||
break;
|
||||
}
|
||||
case SQLITE_INTEGER: {
|
||||
i64 iVal = sqlite3_value_int64(argv[0]);
|
||||
double rVal = (double)iVal;
|
||||
if( iVal==rVal ){
|
||||
sqlite3_result_double(context, rVal);
|
||||
return;
|
||||
}
|
||||
sqlite3_result_null(context);
|
||||
break;
|
||||
}
|
||||
case SQLITE_BLOB:
|
||||
case SQLITE_TEXT: {
|
||||
const unsigned char *zStr = sqlite3_value_text(argv[0]);
|
||||
|
Reference in New Issue
Block a user