From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: [tarantool-patches] [PATCH v2 2/8] decimal: fix encoding numbers with positive exponent. From: Serge Petrenko In-Reply-To: <20190812211838.GD32337@atlas> Date: Tue, 13 Aug 2019 12:00:46 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <72BD3FFE-9D36-41DA-B11D-2E30E9A5D294@tarantool.org> References: <53d58fa5cad01273d3e60fe034c8e74f023d3c0e.1565263272.git.sergepetrenko@tarantool.org> <20190812211838.GD32337@atlas> To: Konstantin Osipov Cc: Vladimir Davydov , tarantool-patches@freelists.org List-ID: > 13 =D0=B0=D0=B2=D0=B3. 2019 =D0=B3., =D0=B2 0:18, Konstantin Osipov = =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB(=D0=B0):= >=20 > * Serge Petrenko [19/08/08 14:56]: >> When a number having a positive exponent is encoded, the internal >> decPackedFromNumber function returns a negative scale, which differs >> from the scale, returned by decimal_scale(). This leads to errors in >> decoding. Account for negative scale in decimal_pack() and >> decimal_unpack(). >=20 > I don't understand this commit. >=20 > Why do you use mp_store_u8 + a cast to unsigned, not > mp_store_i8/mp_load_i8 without a cast? We don=E2=80=99t have mp_store_i8/mp_load_i8, we only have mp_load(store)_u8/16/32/64, and mp_store(load)_u8 is used to put(get) a single byte into(from) the buffer. Besides, I don=E2=80=99t know how should an implementation of = mp_store_i8 look like. Will it be a cast to unsigned and a call to mp_store_u8? I could use mp_encode_int(), but it would require an additional byte for scales less than -31. Why waste a byte? Similar code is already used in mp_encode_extl/mp_decode_extl() (yes, it was also introduced by me, but it passed the review): (the type of =E2=80=99type=E2=80=99 is int8_t) data =3D mp_store_u8(data, type); =E2=80=A6 *type =3D mp_load_u8(data); >=20 >=20 > --=20 > Konstantin Osipov, Moscow, Russia >=20 -- Serge Petrenko sergepetrenko@tarantool.org