]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
As a special case, casting '-0.0' into numeric should yield 0.
authordrh <drh@noemail.net>
Wed, 12 Jun 2019 20:51:38 +0000 (20:51 +0000)
committerdrh <drh@noemail.net>
Wed, 12 Jun 2019 20:51:38 +0000 (20:51 +0000)
Fix for ticket [674385aeba91c774].

FossilOrigin-Name: 491f0f9bbddb6302536d99abd1ea481fd747ddcf6c6eaaacc0338d147b119081

manifest
manifest.uuid
src/vdbemem.c
test/cast.test

index 77216e85fb98e49da611ce1fa93551bf03ec751a..098d8984ab3b47bb5d905a61b48c386ebac8199e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Handle\sexpressions\slike\s"expr\sIS\sTRUE\sCOLLATE\sxyz"\sin\sthe\ssame\sway\sas\s"expr\sIS\sTRUE".\sFix\sfor\s[4d01eda8115b10d1].
-D 2019-06-12T13:49:32.380
+C As\sa\sspecial\scase,\scasting\s'-0.0'\sinto\snumeric\sshould\syield\s0.\nFix\sfor\sticket\s[674385aeba91c774].
+D 2019-06-12T20:51:38.407
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -600,7 +600,7 @@ F src/vdbeInt.h 3ba14553508d66f58753952d6dd287dce4ec735de02c6440858b4891aed51c17
 F src/vdbeapi.c f9161e5c77f512fbb80091ce8af621d19c9556bda5e734cffaac1198407400da
 F src/vdbeaux.c 3a803d75875031309204df90977059b12ffb706d16b4baa5e2d99f4353962582
 F src/vdbeblob.c f5c70f973ea3a9e915d1693278a5f890dc78594300cf4d54e64f2b0917c94191
-F src/vdbemem.c c970d2b480beca04f9a6a70be70acf07aa1aa261f7a723e5beb986d1a83cd851
+F src/vdbemem.c 9ee3c0373bfc05dc8bf5307a4a92be6bea3055928c4846fdced7e708993b2d6d
 F src/vdbesort.c 66592d478dbb46f19aed0b42222325eadb84deb40a90eebe25c6e7c1d8468f47
 F src/vdbetrace.c fa3bf238002f0bbbdfb66cc8afb0cea284ff9f148d6439bc1f6f2b4c3b7143f0
 F src/vtab.c 1fa256c6ddad7a81e2a4dc080d015d4b0a7135767717d311298e47f6fca64bb3
@@ -723,7 +723,7 @@ F test/capi3b.test efb2b9cfd127efa84433cd7a2d72ce0454ae0dc4
 F test/capi3c.test 54e2dc0c8fd7c34ad1590d1be6864397da2438c95a9f5aee2f8fbc60c112e44b
 F test/capi3d.test aba917805573a03deed961a21f07a5a84505ad0a616f7e3fc1508844a15bccc4
 F test/capi3e.test 3d49c01ef2a1a55f41d73cba2b23b5059ec460fe
-F test/cast.test 2067a08edfe4ded14d0eb845731716d397df78d65b69d8045d25950ad9bffad9
+F test/cast.test 6678564470f08a638425d38d7e33da2a3af9b121c7c4136712997e02a250974f
 F test/cffault.test 9d6b20606afe712374952eec4f8fd74b1a8097ef
 F test/check.test dcc952a127c394ce0de2aa634d26c78207e855327cc63a24d3638ca8fbfa641e
 F test/chunksize.test 427d87791743486cbf0c3b8c625002f3255cb3a89c6eba655a98923b1387b760
@@ -1830,7 +1830,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 614ecb0af47038848e8ba2aed6b92db6f33ddc4aea6361795dbde440380f5a35
-R ff535e67a0f998f18172bd430f50d3e5
-U dan
-Z 1b38c763ebe911ce5080403db6734d6a
+P 5c6146b56a75a94f4baa10e95407c54dd0b9314a57a8702a4b96b15c4d7ac48c
+R 6c86d629a66a89517c28e86d21d1e096
+U drh
+Z 50b8926736baa22469a105aadf87c0d7
index 0c3952791585362633b83080bbf3d4e15d080330..38b5f79abc02bf36629ff88fe207a4bfdaeaf9bf 100644 (file)
@@ -1 +1 @@
-5c6146b56a75a94f4baa10e95407c54dd0b9314a57a8702a4b96b15c4d7ac48c
\ No newline at end of file
+491f0f9bbddb6302536d99abd1ea481fd747ddcf6c6eaaacc0338d147b119081
\ No newline at end of file
index 20e1fb77e0b599a3f237f132cfdfaaddabb9d3f7..c0e386ef6d2cae2b1d8df57033f5dc64ea91a660 100644 (file)
@@ -693,14 +693,17 @@ int sqlite3VdbeMemRealify(Mem *pMem){
 /* Compare a floating point value to an integer.  Return true if the two
 ** values are the same within the precision of the floating point value.
 **
+** This function assumes that i was obtained by assignment from r1.
+**
 ** For some versions of GCC on 32-bit machines, if you do the more obvious
 ** comparison of "r1==(double)i" you sometimes get an answer of false even
 ** though the r1 and (double)i values are bit-for-bit the same.
 */
 int sqlite3RealSameAsInt(double r1, sqlite3_int64 i){
   double r2 = (double)i;
-  return memcmp(&r1, &r2, sizeof(r1))==0
-      && i >= -2251799813685248 && i < 2251799813685248;
+  return r1==0.0
+      || (memcmp(&r1, &r2, sizeof(r1))==0
+          && i >= -2251799813685248 && i < 2251799813685248);
 }
 
 /*
index 09127ee985888c677dce8fa9086e2af7b25b10b9..5e134abed63f6a197a2fe57f7aafad2af6b7bcaa 100644 (file)
@@ -183,34 +183,34 @@ do_test cast-1.53 {
   execsql {SELECT CAST('123.5abc' AS integer)}
 } 123
 
-do_test case-1.60 {
+do_test cast-1.60 {
   execsql {SELECT CAST(null AS REAL)}
 } {{}}
-do_test case-1.61 {
+do_test cast-1.61 {
   execsql {SELECT typeof(CAST(null AS REAL))}
 } {null}
-do_test case-1.62 {
+do_test cast-1.62 {
   execsql {SELECT CAST(1 AS REAL)}
 } {1.0}
-do_test case-1.63 {
+do_test cast-1.63 {
   execsql {SELECT typeof(CAST(1 AS REAL))}
 } {real}
-do_test case-1.64 {
+do_test cast-1.64 {
   execsql {SELECT CAST('1' AS REAL)}
 } {1.0}
-do_test case-1.65 {
+do_test cast-1.65 {
   execsql {SELECT typeof(CAST('1' AS REAL))}
 } {real}
-do_test case-1.66 {
+do_test cast-1.66 {
   execsql {SELECT CAST('abc' AS REAL)}
 } {0.0}
-do_test case-1.67 {
+do_test cast-1.67 {
   execsql {SELECT typeof(CAST('abc' AS REAL))}
 } {real}
-do_test case-1.68 {
+do_test cast-1.68 {
   execsql {SELECT CAST(x'31' AS REAL)}
 } {1.0}
-do_test case-1.69 {
+do_test cast-1.69 {
   execsql {SELECT typeof(CAST(x'31' AS REAL))}
 } {real}
 
@@ -299,7 +299,7 @@ if {[db eval {PRAGMA encoding}]=="UTF-8"} {
     } 9223372036854774784
   }
 }
-do_test case-3.31 {
+do_test cast-3.31 {
   execsql {SELECT CAST(NULL AS numeric)}
 } {{}}
 
@@ -368,7 +368,7 @@ do_execsql_test cast-5.2 {
 # ignored because it is no part of the integer prefix.
 # EVIDENCE-OF: R-24225-46995 For example, "(CAST '123e+5' AS INTEGER)"
 # results in 123, not in 12300000.
-do_execsql_test case-5.3 {
+do_execsql_test cast-5.3 {
   SELECT CAST('123e+5' AS INTEGER);
   SELECT CAST('123e+5' AS NUMERIC);
   SELECT CAST('123e+5' AS REAL);
@@ -378,7 +378,7 @@ do_execsql_test case-5.3 {
 # The following does not have anything to do with the CAST operator,
 # but it does deal with affinity transformations.
 #
-do_execsql_test case-6.1 {
+do_execsql_test cast-6.1 {
   DROP TABLE IF EXISTS t1;
   CREATE TABLE t1(a NUMERIC);
   INSERT INTO t1 VALUES
@@ -391,28 +391,28 @@ do_execsql_test case-6.1 {
 
 # 2019-06-07
 # https://www.sqlite.org/src/info/4c2d7639f076aa7c
-do_execsql_test case-7.1 {
+do_execsql_test cast-7.1 {
   SELECT CAST('-' AS NUMERIC);
 } {0}
-do_execsql_test case-7.2 {
+do_execsql_test cast-7.2 {
   SELECT CAST('-0' AS NUMERIC);
 } {0}
-do_execsql_test case-7.3 {
+do_execsql_test cast-7.3 {
   SELECT CAST('+' AS NUMERIC);
 } {0}
-do_execsql_test case-7.4 {
+do_execsql_test cast-7.4 {
   SELECT CAST('/' AS NUMERIC);
 } {0}
 
 # 2019-06-07
 # https://www.sqlite.org/src/info/e8bedb2a184001bb
-do_execsql_test case-7.10 {
+do_execsql_test cast-7.10 {
   SELECT '' - 2851427734582196970;
 } {-2851427734582196970}
-do_execsql_test case-7.11 {
+do_execsql_test cast-7.11 {
   SELECT 0 - 2851427734582196970;
 } {-2851427734582196970}
-do_execsql_test case-7.12 {
+do_execsql_test cast-7.12 {
   SELECT '' - 1;
 } {-1}
 
@@ -447,5 +447,22 @@ do_execsql_test cast-7.33 {
   SELECT -CAST('.' AS numeric);
 } 0
 
+# 2019-06-12
+# https://www.sqlite.org/src/info/674385aeba91c774
+#
+do_execsql_test cast-7.40 {
+  SELECT CAST('-0.0' AS numeric);
+} 0
+do_execsql_test cast-7.41 {
+  SELECT CAST('0.0' AS numeric);
+} 0
+do_execsql_test cast-7.42 {
+  SELECT CAST('+0.0' AS numeric);
+} 0
+do_execsql_test cast-7.43 {
+  SELECT CAST('-1.0' AS numeric);
+} -1
+
+
 
 finish_test