aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2023-07-01 18:33:26 +0000
committerdrh <>2023-07-01 18:33:26 +0000
commit453be55b85d98ab55d7398cbebf81f413d1d7794 (patch)
tree2defb4ed387775ebb3db146cfb083e94038e7528 /src
parent17c20bb15e5f51e12efd95fd3dc8806f939d8af8 (diff)
downloadsqlite-453be55b85d98ab55d7398cbebf81f413d1d7794.tar.gz
sqlite-453be55b85d98ab55d7398cbebf81f413d1d7794.zip
Reinstate the fpdecode() SQL function for testing, but only when compiled
with SQLITE_DEBUG. FossilOrigin-Name: 07eab52e0801bb0e4743b304a06ad16e18cdf8eaa18c0faf8d47a1f5d8576ea0
Diffstat (limited to 'src')
-rw-r--r--src/func.c34
-rw-r--r--src/printf.c2
2 files changed, 35 insertions, 1 deletions
diff --git a/src/func.c b/src/func.c
index 07ada2ef6..c6a49de61 100644
--- a/src/func.c
+++ b/src/func.c
@@ -2371,6 +2371,37 @@ static void signFunc(
sqlite3_result_int(context, x<0.0 ? -1 : x>0.0 ? +1 : 0);
}
+#ifdef SQLITE_DEBUG
+/*
+** Implementation of fpdecode(x,y,z) function.
+**
+** x is a real number that is to be decoded. y is the precision.
+** z is the maximum real precision.
+*/
+static void fpdecodeFunc(
+ sqlite3_context *context,
+ int argc,
+ sqlite3_value **argv
+){
+ FpDecode s;
+ double x;
+ int y, z;
+ char zBuf[100];
+ UNUSED_PARAMETER(argc);
+ assert( argc==3 );
+ x = sqlite3_value_double(argv[0]);
+ y = sqlite3_value_int(argv[1]);
+ z = sqlite3_value_int(argv[2]);
+ sqlite3FpDecode(&s, x, y, z);
+ if( s.isSpecial==2 ){
+ sqlite3_snprintf(sizeof(zBuf), zBuf, "NaN");
+ }else{
+ sqlite3_snprintf(sizeof(zBuf), zBuf, "%c%.*s/%d", s.sign, s.n, s.z, s.iDP);
+ }
+ sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
+}
+#endif /* SQLITE_DEBUG */
+
/*
** All of the FuncDef structures in the aBuiltinFunc[] array above
** to the global function hash table. This occurs at start-time (as
@@ -2442,6 +2473,9 @@ void sqlite3RegisterBuiltinFunctions(void){
FUNCTION(unicode, 1, 0, 0, unicodeFunc ),
FUNCTION(char, -1, 0, 0, charFunc ),
FUNCTION(abs, 1, 0, 0, absFunc ),
+#ifdef SQLITE_DEBUG
+ FUNCTION(fpdecode, 3, 0, 0, fpdecodeFunc ),
+#endif
#ifndef SQLITE_OMIT_FLOATING_POINT
FUNCTION(round, 1, 0, 0, roundFunc ),
FUNCTION(round, 2, 0, 0, roundFunc ),
diff --git a/src/printf.c b/src/printf.c
index f00ad4cb2..3fb1a322a 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -202,7 +202,6 @@ void sqlite3_str_vappendf(
int nOut; /* Size of the rendering buffer */
char *zExtra = 0; /* Malloced memory used by some conversion */
int exp, e2; /* exponent of real numbers */
- int j; /* Number of significant digits returned */
etByte flag_dp; /* True if decimal point should be shown */
etByte flag_rtz; /* True if trailing zeros should be removed */
@@ -483,6 +482,7 @@ void sqlite3_str_vappendf(
case etGENERIC: {
FpDecode s;
int iRound;
+ int j;
if( bArgList ){
realvalue = getDoubleArg(pArgList);