From: Stanislav Zudin <szudin@tarantool.org> To: tarantool-patches@freelists.org, vdavydov.dev@gmail.com Cc: Stanislav Zudin <szudin@tarantool.org> Subject: [PATCH 06/13] sql: aux functions to support big integers Date: Fri, 15 Mar 2019 18:45:35 +0300 [thread overview] Message-ID: <df5ffbd9794bb9fefa106ebd5d28dc1d39035bcb.1552663061.git.szudin@tarantool.org> (raw) In-Reply-To: <cover.1552663061.git.szudin@tarantool.org> In-Reply-To: <cover.1552663061.git.szudin@tarantool.org> Adapts auxiliary functions for supporting arithmetic operations with unsigned integers. --- src/box/sql/vdbe.c | 21 ++++++++++++++------- src/box/sql/vdbemem.c | 3 +++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index 8a7f7a12f..ea9d9d98f 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -404,15 +404,20 @@ sql_value_apply_type( * numeric type, if has one. Set the pMem->u.r and pMem->u.i fields * accordingly. */ -static u16 SQL_NOINLINE computeNumericType(Mem *pMem) +static u32 SQL_NOINLINE computeNumericType(Mem *pMem) { assert((pMem->flags & (MEM_Int|MEM_Real))==0); assert((pMem->flags & (MEM_Str|MEM_Blob))!=0); if (sqlAtoF(pMem->z, &pMem->u.r, pMem->n)==0) return 0; - if (sql_atoi64(pMem->z, (int64_t *)&pMem->u.i, pMem->n)==ATOI_SIGNED) - return MEM_Int; - return MEM_Real; + switch(sql_atoi64(pMem->z, (int64_t *)&pMem->u.i, pMem->n)) { + case ATOI_SIGNED: + return MEM_Int; + case ATOI_UNSIGNED: + return MEM_Int | MEM_Unsigned; + default: /* ATOI_OVERFLOW:*/ + return MEM_Real; + } } /* @@ -422,8 +427,10 @@ static u16 SQL_NOINLINE computeNumericType(Mem *pMem) * Unlike mem_apply_numeric_type(), this routine does not modify pMem->flags. * But it does set pMem->u.r and pMem->u.i appropriately. */ -static u16 numericType(Mem *pMem) +static u32 numericType(Mem *pMem) { + if ((pMem->flags & (MEM_Int|MEM_Unsigned)) == (MEM_Int|MEM_Unsigned)) + return (MEM_Int|MEM_Unsigned); if (pMem->flags & (MEM_Int|MEM_Real)) { return pMem->flags & (MEM_Int|MEM_Real); } @@ -1648,8 +1655,8 @@ case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */ case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */ char bIntint; /* Started out as two integer operands */ u32 flags; /* Combined MEM_* flags from both inputs */ - u16 type1; /* Numeric type of left operand */ - u16 type2; /* Numeric type of right operand */ + u32 type1; /* Numeric type of left operand */ + u32 type2; /* Numeric type of right operand */ i64 iA; /* Integer value of left operand */ i64 iB; /* Integer value of right operand */ double rA; /* Real value of left operand */ diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c index 5e35a1720..2805d7a01 100644 --- a/src/box/sql/vdbemem.c +++ b/src/box/sql/vdbemem.c @@ -489,6 +489,9 @@ sqlVdbeRealValue(Mem * pMem, double *v) if (pMem->flags & MEM_Real) { *v = pMem->u.r; return 0; + } else if (pMem->flags & (MEM_Int | MEM_Unsigned)) { + *v = (double)(u64)pMem->u.i; + return 0; } else if (pMem->flags & MEM_Int) { *v = (double)pMem->u.i; return 0; -- 2.17.1
next prev parent reply other threads:[~2019-03-15 15:45 UTC|newest] Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-03-15 15:45 [PATCH 00/13] sql: support -2^63 .. 2^64-1 integer type Stanislav Zudin 2019-03-15 15:45 ` [PATCH 01/13] sql: Convert big integers from string Stanislav Zudin 2019-03-25 15:10 ` [tarantool-patches] " n.pettik 2019-04-01 20:39 ` Stanislav Zudin 2019-04-02 7:27 ` Konstantin Osipov 2019-03-15 15:45 ` [PATCH 02/13] sql: make VDBE recognize big integers Stanislav Zudin 2019-03-25 15:11 ` [tarantool-patches] " n.pettik 2019-04-01 20:42 ` Stanislav Zudin 2019-04-02 7:38 ` [tarantool-patches] " Konstantin Osipov 2019-03-15 15:45 ` [PATCH 03/13] sql: removes unused function Stanislav Zudin 2019-03-25 15:11 ` [tarantool-patches] " n.pettik 2019-04-01 20:39 ` Stanislav Zudin 2019-03-15 15:45 ` [PATCH 04/13] sql: support big integers within sql binding Stanislav Zudin 2019-03-25 15:12 ` [tarantool-patches] " n.pettik 2019-04-01 20:42 ` Stanislav Zudin 2019-04-02 7:46 ` Konstantin Osipov 2019-04-02 7:44 ` [tarantool-patches] " Konstantin Osipov 2019-03-15 15:45 ` [PATCH 05/13] sql: removes redundant function Stanislav Zudin 2019-03-25 15:12 ` [tarantool-patches] " n.pettik 2019-03-15 15:45 ` Stanislav Zudin [this message] 2019-03-25 15:13 ` [tarantool-patches] Re: [PATCH 06/13] sql: aux functions to support big integers n.pettik 2019-03-15 15:45 ` [PATCH 07/13] sql: arithmetic functions " Stanislav Zudin 2019-03-25 15:13 ` [tarantool-patches] " n.pettik 2019-04-01 20:43 ` Stanislav Zudin 2019-04-02 7:54 ` Konstantin Osipov 2019-04-02 7:52 ` Konstantin Osipov 2019-03-15 15:45 ` [PATCH 08/13] sql: aggregate sql functions support big int Stanislav Zudin 2019-03-25 15:13 ` [tarantool-patches] " n.pettik 2019-04-01 20:43 ` Stanislav Zudin 2019-04-02 7:57 ` [tarantool-patches] " Konstantin Osipov 2019-03-15 15:45 ` [PATCH 09/13] sql: fixes errors Stanislav Zudin 2019-03-25 15:14 ` [tarantool-patches] " n.pettik 2019-03-15 15:45 ` [PATCH 10/13] sql: fixes an error in sqlSubInt64 Stanislav Zudin 2019-03-25 15:14 ` [tarantool-patches] " n.pettik 2019-03-15 15:45 ` [PATCH 11/13] sql: fixes an error in string to int64 conversion Stanislav Zudin 2019-03-25 15:14 ` [tarantool-patches] " n.pettik 2019-03-15 15:45 ` [PATCH 12/13] sql: fixes an error in uint64 to double casting Stanislav Zudin 2019-03-25 15:15 ` [tarantool-patches] " n.pettik 2019-03-15 15:45 ` [PATCH 13/13] sql: support -2^63 .. 2^64-1 integer type Stanislav Zudin 2019-03-25 15:25 ` [tarantool-patches] " n.pettik 2019-04-01 20:44 ` Stanislav Zudin 2019-03-25 15:10 ` [tarantool-patches] Re: [PATCH 00/13] " n.pettik 2019-04-01 20:38 ` Stanislav Zudin
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=df5ffbd9794bb9fefa106ebd5d28dc1d39035bcb.1552663061.git.szudin@tarantool.org \ --to=szudin@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=vdavydov.dev@gmail.com \ --subject='Re: [PATCH 06/13] sql: aux functions to support big integers' \ /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