[tarantool-patches] [PATCH v2 2/8] decimal: fix encoding numbers with positive exponent.

Serge Petrenko sergepetrenko at tarantool.org
Tue Aug 13 12:00:46 MSK 2019



> 13 авг. 2019 г., в 0:18, Konstantin Osipov <kostja at tarantool.org> написал(а):
> 
> * Serge Petrenko <sergepetrenko at tarantool.org> [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().
> 
> I don't understand this commit.
> 
> Why do you use mp_store_u8 + a cast to unsigned, not
> mp_store_i8/mp_load_i8 without a cast?

We don’t 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’t 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 ’type’ is int8_t)
         data = mp_store_u8(data, type);
…
         *type = mp_load_u8(data);
> 
> 
> -- 
> Konstantin Osipov, Moscow, Russia
> 

--
Serge Petrenko
sergepetrenko at tarantool.org




More information about the Tarantool-patches mailing list