Tarantool development patches archive
 help / color / mirror / Atom feed
From: Serge Petrenko <sergepetrenko@tarantool.org>
To: Konstantin Osipov <kostja@tarantool.org>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>,
	tarantool-patches@freelists.org
Subject: Re: [tarantool-patches] Re: [PATCH] decimal: add methods truncate and set_scale
Date: Fri, 19 Jul 2019 15:15:11 +0300	[thread overview]
Message-ID: <B524BCAA-4C58-45B9-A768-6E3A0F9BC85F@tarantool.org> (raw)
In-Reply-To: <20190719115746.GA29078@atlas>


> 19 июля 2019 г., в 14:57, Konstantin Osipov <kostja@tarantool.org> написал(а):
> 
> * Serge Petrenko <sergepetrenko@tarantool.org> [19/07/19 14:42]:
>> This patch adds 2 methods to decimal library and lua module:
>> truncate will remove all trailing fractional zeros and set_scale will
>> either perform rounding or append excess fractional zeros.
>> 
> 
> Please note that it is Trim in the ldec library.
> truncate() has a slightly different meaning.
> 
>> +decimal_t *
>> +decimal_truncate(decimal_t *dec)
>> +{
>> +	decimal_t *res = decNumberTrim(dec);
>> +
>> +	/* No errors are possible */
>> +	assert(res == dec);
>> +	return res;
>> +}
>> +
>> +decimal_t *
>> +decimal_set_scale(decimal_t *dec, int scale)
>> +{
>> +	if (scale < 0)
>> +		return NULL;
>> +	if (scale <= decimal_scale(dec))
>> +		return decimal_round(dec, scale);
>> +	/* how much zeros shoud we append. */
>> +	int delta = scale + dec->exponent;
>> +	if (scale > DECIMAL_MAX_DIGITS || dec->digits + delta > DECIMAL_MAX_DIGITS)
>> +		return NULL;
>> +	decimal_t new_scale;
>> +	decimal_from_int64(&new_scale, -scale);
>> +	decNumberRescale(dec, dec, &new_scale, &decimal_context);
>> +	assert(decimal_check_status(dec, &decimal_context) != NULL);
>> +	return dec;
> 
> Please also note here: the name is rescale(), not set_scale(). The
> meaning of set_scale() is slightly different.
> 
> Please use less confusing names.

Hi! Thank you for review.
No problem, renamed to trim() and rescale().
The changes are on the branch.

> 
> otherwise lgtm.
> 
> -- 
> Konstantin Osipov, Moscow, Russia
> 


--
Serge Petrenko
sergepetrenko@tarantool.org

  reply	other threads:[~2019-07-19 12:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-19 11:21 Serge Petrenko
2019-07-19 11:57 ` [tarantool-patches] " Konstantin Osipov
2019-07-19 12:15   ` Serge Petrenko [this message]
2019-07-24 11:42     ` [tarantool-patches] " Vladimir Davydov

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=B524BCAA-4C58-45B9-A768-6E3A0F9BC85F@tarantool.org \
    --to=sergepetrenko@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [tarantool-patches] Re: [PATCH] decimal: add methods truncate and set_scale' \
    /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