From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 6E4626ECE3; Mon, 27 Jun 2022 16:54:44 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6E4626ECE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1656338084; bh=31MpmsO28kuKGb3m3SidTTekI7HcvXoLLrpiuKcbX2Y=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=O3TlUUcok0umNryKzlOPgrteywwqmht1Fo0jILuvGTEEfBT5e06kwv9uaoznMTIly /Rf3KKwIBQSIFrCI58ewV8TZz9Ov9mnladRDNJLiMnp/2ygb8HN3gJMruScfey0s4J +dCAwtqsHwrcD3bMo77i6boGEklvjkyvfsJFFugg= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id D37BE6ECE3 for ; Mon, 27 Jun 2022 16:54:42 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D37BE6ECE3 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1o5pCL-0005w3-S0; Mon, 27 Jun 2022 16:54:42 +0300 Date: Mon, 27 Jun 2022 16:47:31 +0300 To: Sergey Kaplun Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Clacks-Overhead: GNU Terry Pratchett X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD921FF253C2DCA64321B2EC99CF25E63D65830E91EC7FA074800894C459B0CD1B9B9DAF7F78C4FC40C4E67237E660AFEAC7A52375B7A7270F1AF0056C46A67EA41 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE73C696014E2DCCA1EEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006375E7A1B5661595F038638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8CDD0DF1E19A4995AD322F94C6BF07111117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8B47272755C61AA17BA471835C12D1D977C4224003CC8364762BB6847A3DEAEFB0F43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7CDDB9BF3B882869D543847C11F186F3C59DAA53EE0834AAEE X-8FC586DF: 6EFBBC1D9D64D975 X-C1DE0DAB: 9604B64F49C60606AD91A466A1DEF99B296C473AB1E14218C6CDE5D1141D2B1CB175BEF9C4676AC13CF99A44FC32FCC80F396BC0B0FADB93AD91A466A1DEF99B296C473AB1E14218B936CB490224F2464EEA7BD89490CAC0EDDA962BC3F61961 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D346E67BC984B8ABCB500771B0BD0631B2413EF442855E8D4B6E5489AB98E503CB042354AEC60EA9D7B1D7E09C32AA3244C5E4F59161CD5F939791275F16EFD1504B038C9161EF167A1927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj8L65zF8kk4cjfY7749V9uA== X-Mailru-Sender: 689FA8AB762F7393CC2E0F076E87284ECD12BB6A09F1A950B6EA1ACDF43B7C64A7C8D0F45F857DBFE9F1EFEE2F478337FB559BB5D741EB964C8C2C849690F8E70A04DAD6CC59E3365FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 1/2] Fix tonumber("-0"). X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Igor Munkin via Tarantool-patches Reply-To: Igor Munkin Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Sergey, Thanks for the patch! LGTM, with two nits, I've fixed on the branch by myself. On 26.01.22, Sergey Kaplun wrote: > From: Mike Pall > > Reported by bluecheetah001. > > (cherry picked from 45a7e5073ce0a59465fef0b80bb08bd4e76b7979) > > Common case for scanning a string containing a number is a string with a > decimal number. For this case, a decimal number first casts to int32_t > and later to double (lua_Number) if necessary. Information about sign of > 0 is lost during the cast to int32_t. So resulting TValue contains `0.` > instead of `-0.`. > > This patch removes cast to int32_t for the case when resulting TValue > contains double value. Minor: I propose the following wording (it looks a bit more clear to me at least): | When an integral decimal number is given to `tonumber`, it is casted to | int32_t at first and later to double (lua_Number) if necessary. | Information about sign of 0 is lost during the cast to int32_t. So | resulting TValue contains `0.` instead of `-0.`. | | This patch removes cast to int32_t for the cases when the input number | can't be represented by an integer. > > Sergey Kaplun: > * added the description and the test for the problem > > Part of tarantool/tarantool#6548 > --- > src/lj_strscan.c | 5 ++--- > .../lj-528-tonumber-0.test.lua | 19 +++++++++++++++++++ > 2 files changed, 21 insertions(+), 3 deletions(-) > create mode 100644 test/tarantool-tests/lj-528-tonumber-0.test.lua > > diff --git a/test/tarantool-tests/lj-528-tonumber-0.test.lua b/test/tarantool-tests/lj-528-tonumber-0.test.lua > new file mode 100644 > index 00000000..03ba2aff > --- /dev/null > +++ b/test/tarantool-tests/lj-528-tonumber-0.test.lua > @@ -0,0 +1,19 @@ > +local tap = require('tap') > + > +-- Test disabled for DUALNUM mode default for some arches. > +-- See also https://github.com/LuaJIT/LuaJIT/pull/787. > +require("utils").skipcond( > + jit.arch ~= "x86" and jit.arch ~= "x64", > + jit.arch.." in DUALNUM mode is clumsy for now" > +) Minor: Use single quotes instead of the double ones. > + > +-- Test file to demonstrate LuaJIT `tonumber('-0')` incorrect > +-- behaviour. > +-- See also https://github.com/LuaJIT/LuaJIT/issues/528. > +local test = tap.test('lj-528-tonumber-0') > +test:plan(1) > + > +-- As numbers `-0 == 0`, so convert it back to string. > +test:ok(tostring(tonumber('-0')) == '-0', 'correct "-0" string parsing') > + > +os.exit(test:check() and 0 or 1) > -- > 2.34.1 > -- Best regards, IM