From: drh Date: Mon, 27 May 2019 00:29:15 +0000 (+0000) Subject: Improved rounding even on systems with an 8-byte "long double" type. X-Git-Tag: version-3.29.0~65 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ef7d5187a74fdddee3dabfaddebaf63ca316aac7;p=thirdparty%2Fsqlite.git Improved rounding even on systems with an 8-byte "long double" type. FossilOrigin-Name: 15202aee150fa8e15fb90e90e5765c5e19a1eaf4896da2996a747636b76da8e6 --- diff --git a/manifest b/manifest index 22c51be6ab..35606de1a9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Performance\senhancement\sin\ssqlite3AtoF().\s\sAbout\s8%\sfaster. -D 2019-05-25T18:17:53.260 +C Improved\srounding\seven\son\ssystems\swith\san\s8-byte\s"long\sdouble"\stype. +D 2019-05-27T00:29:15.840 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -518,7 +518,7 @@ F src/pcache1.c be64b2f3908a7f97c56c963676eb12f0d6254c95b28cdc1d73a186eff213219d F src/pragma.c 925bcac0afd98a0d4255c7524b93239ab4d83893d96f7f8fdccd78d4929a39bb F src/pragma.h 4a9fabff14db4487a734dfeeb4be984ce662bfdccfae16145b9c732327735e13 F src/prepare.c 78027c6231fbb19ca186a5f5f0c0a1375d9c2cec0655273f9bd90d9ff74a34b3 -F src/printf.c 23a0fd3c81637d3d05340919d8a65963091e5f6597db1d275cdc9742dd970165 +F src/printf.c 9be6945837c839ba57837b4bc3af349eba630920fa5532aa518816defe42a7d4 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c bae0a7562db77b02d87101b587819d5a5dcd8625e477d2d8a228a20bba4fead6 F src/rowset.c d977b011993aaea002cab3e0bb2ce50cf346000dff94e944d547b989f4b1fe93 @@ -1244,7 +1244,7 @@ F test/resolver01.test f4022acafda7f4d40eca94dbf16bc5fc4ac30ceb F test/rollback.test 06680159bc6746d0f26276e339e3ae2f951c64812468308838e0a3362d911eaa F test/rollback2.test bc868d57899dc6972e2b4483faae0e03365a0556941474eec487ae21d8d38bb6 F test/rollbackfault.test 0e646aeab8840c399cfbfa43daab46fd609cf04a -F test/round1.test 138fc19eb8798fac8a475e3c624b8d7736ea12b65ecef43bb6bcf071b3c63a81 +F test/round1.test 768018b04522ca420b1aba8a24bd76091d269f3bce3902af3ec6ebcee41ab21e F test/rowallock.test 3f88ec6819489d0b2341c7a7528ae17c053ab7cc F test/rowhash.test 0bc1d31415e4575d10cacf31e1a66b5cc0f8be81 F test/rowid.test bfbd7b97d9267660be3c8f28507c4ed7f205196b8877c0db42df347c2e8845e3 @@ -1829,7 +1829,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 2e2ebad3ab636c4c65814ad41d417b105be8e254d609d0e08fbba4c5bd107bf3 -R ef9208359f9605c768184cd8045692e9 +P 81721aa54587e20d031d528fb6b74d91671a6e950fa926dc63f4284466e70f0e +R c9de0c36c0333668e5f2f8e4d611250f U drh -Z f6f659f82b7441453c2104f0c0b3b1fb +Z 1cb14885af88ddd3e3ec785d1bef950d diff --git a/manifest.uuid b/manifest.uuid index 776837a336..3dafc063a2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -81721aa54587e20d031d528fb6b74d91671a6e950fa926dc63f4284466e70f0e \ No newline at end of file +15202aee150fa8e15fb90e90e5765c5e19a1eaf4896da2996a747636b76da8e6 \ No newline at end of file diff --git a/src/printf.c b/src/printf.c index f1634799ba..fc77f68dff 100644 --- a/src/printf.c +++ b/src/printf.c @@ -527,7 +527,12 @@ void sqlite3_str_vappendf( rounder = arRound[idx%10]; while( idx>=10 ){ rounder *= 1.0e-10; idx -= 10; } if( xtype==etFLOAT ){ - if( precision<17) rounder += realvalue*2.0e-16; + double rx = (double)realvalue; + sqlite3_uint64 u; + int ex; + memcpy(&u, &rx, sizeof(u)); + ex = -1023 + (int)((u>>52)&0x7ff); + if( precision+(ex/3) < 15 ) rounder += realvalue*3e-16; realvalue += rounder; } /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */ diff --git a/test/round1.test b/test/round1.test index f3c9a81a20..ba2c79eaba 100644 --- a/test/round1.test +++ b/test/round1.test @@ -15,14 +15,9 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl set testprefix round1 -if {$::longdouble_size<=8} { - finish_test - return -} - expr srand(0) unset -nocomplain iTest -for {set iTest 1} {$iTest<=10000} {incr iTest} { +for {set iTest 1} {$iTest<=50000} {incr iTest} { set x1 [expr int(rand()*100000)] set x2 [expr int(rand()*100000)+1000*int(rand()*10000)] set n [expr int(rand()*8)+1]