From: Igor Munkin via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: Sergey Kaplun <skaplun@tarantool.org> Cc: tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH luajit 1/2] Fix tonumber("-0"). Date: Mon, 27 Jun 2022 16:47:31 +0300 [thread overview] Message-ID: <Yrm0824c2u1PmyxV@tarantool.org> (raw) In-Reply-To: <d5ffce0cfe19d9af66d07da94cd4f70379b6b60b.1643199076.git.skaplun@tarantool.org> 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 <mike> > > 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 > <snipped> > 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
next prev parent reply other threads:[~2022-06-27 13:54 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-01-26 12:19 [Tarantool-patches] [PATCH luajit 0/2] Fix tonumber("-0") inconsistencies Sergey Kaplun via Tarantool-patches 2022-01-26 12:19 ` [Tarantool-patches] [PATCH luajit 1/2] Fix tonumber("-0") Sergey Kaplun via Tarantool-patches 2022-06-27 13:47 ` Igor Munkin via Tarantool-patches [this message] 2022-06-27 20:29 ` sergos via Tarantool-patches 2022-01-26 12:19 ` [Tarantool-patches] [PATCH luajit 2/2] Fix tonumber("-0") in dual-number mode Sergey Kaplun via Tarantool-patches 2022-01-27 9:50 ` Sergey Kaplun via Tarantool-patches 2022-06-27 13:48 ` Igor Munkin via Tarantool-patches 2022-06-27 15:51 ` sergos via Tarantool-patches 2022-06-30 12:09 ` [Tarantool-patches] [PATCH luajit 0/2] Fix tonumber("-0") inconsistencies Igor Munkin via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=Yrm0824c2u1PmyxV@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=imun@tarantool.org \ --cc=skaplun@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH luajit 1/2] Fix tonumber("-0").' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox