From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp5.mail.ru (smtp5.mail.ru [94.100.179.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 4C13442F4AD for ; Thu, 25 Jun 2020 17:22:49 +0300 (MSK) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\)) From: Chris Sosnin In-Reply-To: <5ae054f7-2472-a80c-1b3d-1f89ae40f21a@tarantool.org> Date: Thu, 25 Jun 2020 17:22:48 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <423AA7D0-858B-4FAE-9991-55469592F377@tarantool.org> References: <5ae054f7-2472-a80c-1b3d-1f89ae40f21a@tarantool.org> Subject: Re: [Tarantool-patches] [PATCH v2 2/2] Add IsInt method for checking the fractional part of a number List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org Thank you for the review! > On 25 Jun 2020, at 01:23, Vladislav Shpilevoy = wrote: >=20 > Thanks for the patch! >=20 > Technically looks fine. But see two style comments below. >=20 > On 24/06/2020 18:53, Chris Sosnin wrote: >> Currently there is no efficient way to do this. >>=20 >> Needed for tarantool/tarantool#4415 >> --- >> decNumber.c | 27 +++++++++++++++++++++++++++ >> decNumber.h | 1 + >> 2 files changed, 28 insertions(+) >>=20 >> diff --git a/decNumber.c b/decNumber.c >> index e248656..26acec3 100644 >> --- a/decNumber.c >> +++ b/decNumber.c >> @@ -501,6 +501,33 @@ uLong decNumberToUInt64(const decNumber *dn, = decContext *set) { >> return 0; >> } // decNumberToUInt64 >>=20 >> +Flag decNumberIsInt(const decNumber *dn) { >=20 > 1. It seems Flag type is internal. For public API flags the lib uses = int32_t. > For example, look at decNumberIsNormal(), decNumberIsSubnormal(). I agree, Flag is only used inside decNumber.c, I looked at the wrong = function. Fixed. >=20 >> + const Unit *up=3Ddn->lsu; >> + if (dn->exponent>=3D0) { >> + return 1; >> + } >> + else { >> + Int count=3D-dn->exponent; >> + // spin up whole units until reach the Unit with the unit digit >> + for (; count>=3DDECDPUN; up++) { >> + if (*up!=3D0) return 0; >> + count-=3DDECDPUN; >> + } >> + if (count=3D=3D0) return 1; // [a multiple of = DECDPUN] >> + else { // [not multiple of DECDPUN] >> + Int rem; // work >> + // slice off fraction digits and check for non-zero >> + #if DECDPUN<=3D4 >> + rem=3D*up-QUOT10(*up, count)*powers[count]; >> + #else >> + rem=3D*up%powers[count]; // slice off discards >> + #endif >> + if (rem!=3D0) return 0; >> + } >> + } >> + return 1; >> + } // decNumberIsInt >> + >> /* ------------------------------------------------------------------ = */ >> /* to-scientific-string -- conversion to numeric string = */ >> /* to-engineering-string -- conversion to numeric string = */ >> diff --git a/decNumber.h b/decNumber.h >> index ffaa3d8..9d3a7e1 100644 >> --- a/decNumber.h >> +++ b/decNumber.h >> @@ -169,6 +169,7 @@ >> decNumber * decNumberTrim(decNumber *); >> const char * decNumberVersion(void); >> decNumber * decNumberZero(decNumber *); >> + uint8_t decNumberIsInt(const decNumber *dn); >=20 > 2. Better move this to the other Is functions a few lines below. Where > the comment says "Functions for testing decNumbers". Fixed. >=20 >>=20 >> /* Functions for testing decNumbers (normality depends on context) = */ >> int32_t decNumberIsNormal(const decNumber *, decContext *);