Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp3807428ybx; Sat, 9 Nov 2019 03:56:30 -0800 (PST) X-Google-Smtp-Source: APXvYqx4Qt3SQjRe+28Wy+8ngx8A1qw4fK2ZCmYRoi3nalq7e788qjln4dZzqALV2Tm3GehVyKRM X-Received: by 2002:a17:906:3053:: with SMTP id d19mr13720873ejd.109.1573300589896; Sat, 09 Nov 2019 03:56:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573300589; cv=none; d=google.com; s=arc-20160816; b=xQYBRzuz5Fl1lYWs8NcJKW7lMlUIV727jnm9KE2beQiTdtJh7ekPpPcS2NdEX4TlWi zbteWk8TS/dZGOrEVII0S4VNdLnKab+M7cf2i7Xz/+CV7n0VEYF64xORzZAHD7Pwmxwj R7PuPVAuPpwPg0AdiZVJgyQeX7ZG91aJa/PTNfIN0XhfqkegKx4cKYGD6edAv8eq35ba 2NcNwk4kZO+3cvU8zeV5ld6E9Dlw2x3ZuA5b/CDzTunQueiiQ/XEw6kX9tWjegxl2p2y u1x752X/qbliGHQ6FwCzpSbm2W8WHlHwBYahNQ3f+BPlkJ6Km3G/KrgnIabkQGT1sRHc b+Qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=Z2jXEUfPk9ZL59EZCdrxgIZzRRVijX0R87Ke5uBv/t0=; b=AVUKEEVPkRKhu7R/CWRh+dM7zXC511N+NUXqUQOa+UiJZWUImjX9KD//s7kvcE8Xhh MQPwookPCHAe7KlCQxn2aIA3nYYQLOHvVj+Lkl4e7FmBrt8t1kLvZ2FAmzjp1CJncNZ0 ZyTIxAQ0jsAQRFSna4l5AEvITpWWUPhZi/uwAdKe54xP5ZccORfIgVm/ivj+qQUSXPYM XUu7dsgx37bQhqHxCVouV+KrExP+M1njYkUftHzvinmC9EpXEBZItagInlFDn7J1h9ix NgV5EeO1409GIQ5OTwPcjCQqqRHfE+d/6sTg4sVqETB1yD9p+ifk+IVCtkfoqkz2c5rs dSyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uhhq63ib; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m2si1900459ejj.70.2019.11.09.03.56.06; Sat, 09 Nov 2019 03:56:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uhhq63ib; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726390AbfKILzZ (ORCPT + 99 others); Sat, 9 Nov 2019 06:55:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:60186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726252AbfKILzZ (ORCPT ); Sat, 9 Nov 2019 06:55:25 -0500 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1A4C5207FF; Sat, 9 Nov 2019 11:55:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573300524; bh=z1soBy9NAqy5/dz3HxjryiA+YZGAJ0h1B0pagTmu464=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=uhhq63ibHSgSl5sZkm+gJvHyv1VcRofdyHSqUTdn24ZNAAgQODeVpS/TeJENLcRAl UtjcoLZZ8ZWgnCn8u2ZJcCvwM8GpjIL0cOHsIHVU2XMXEPIfvm2KDQpHYFwYbBQJqj L7Vf81LSVn+HFxcNaNMgTJPWgzWkyjPARSjxJVnE= Date: Sat, 9 Nov 2019 11:55:19 +0000 From: Jonathan Cameron To: Alexander Stein Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/1] iio: core: Fix fractional format generation Message-ID: <20191109115519.14ba0bdc@archlinux> In-Reply-To: <4116142.9TFg0imz4M@ws-140106> References: <20190822060607.25339-1-alexander.stein@systec-electronic.com> <4116142.9TFg0imz4M@ws-140106> X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 07 Nov 2019 14:54:52 +0100 Alexander Stein wrote: > Gentle ping > > On Thursday, August 22, 2019, 8:06:07 AM CET Alexander Stein wrote: > > In case the result is -0.3252 tmp0 is 0 after the div_s64_rem, so tmp0 is > > non-negative which results in an output of 0.3252. > > Fix this by explicitly handling the negative sign ourselves. > > > > Signed-off-by: Alexander Stein Apologies. I'd missed this v2 entirely for some reason. It looks correct to me, but as Lars had inputs on v1... Lars, could you take a quick look at this v2 and give an ack if you are happy with it. Thanks, Jonathan > > --- > > Changes in v2: > > * Support vals[0] >= and vals[1] < 0 in IIO_VAL_FRACTIONAL > > * Note: IIO_VAL_FRACTIONAL is untested, as I lack hardware > > * Note2: Currently IIO_VAL_FRACTIONAL is only called with vals[1] from > > in-kernel drivers AFAICS > > > > drivers/iio/industrialio-core.c | 11 +++++++++-- > > 1 file changed, 9 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c > > index 245b5844028d..247338142c87 100644 > > --- a/drivers/iio/industrialio-core.c > > +++ b/drivers/iio/industrialio-core.c > > @@ -568,6 +568,7 @@ static ssize_t __iio_format_value(char *buf, size_t len, unsigned int type, > > { > > unsigned long long tmp; > > int tmp0, tmp1; > > + char *sign; > > bool scale_db = false; > > > > switch (type) { > > @@ -593,11 +594,17 @@ static ssize_t __iio_format_value(char *buf, size_t len, unsigned int type, > > tmp = div_s64((s64)vals[0] * 1000000000LL, vals[1]); > > tmp1 = vals[1]; > > tmp0 = (int)div_s64_rem(tmp, 1000000000, &tmp1); > > - return snprintf(buf, len, "%d.%09u", tmp0, abs(tmp1)); > > + if (vals[1] < 0) { > > + sign = vals[0] >= 0 ? "-" : ""; > > + } else { > > + sign = vals[0] < 0 ? "-" : ""; > > + } > > + return snprintf(buf, len, "%s%u.%09u", sign, abs(tmp0), abs(tmp1)); > > case IIO_VAL_FRACTIONAL_LOG2: > > + sign = vals[0] < 0 ? "-" : ""; > > tmp = shift_right((s64)vals[0] * 1000000000LL, vals[1]); > > tmp0 = (int)div_s64_rem(tmp, 1000000000LL, &tmp1); > > - return snprintf(buf, len, "%d.%09u", tmp0, abs(tmp1)); > > + return snprintf(buf, len, "%s%u.%09u", sign, abs(tmp0), abs(tmp1)); > > case IIO_VAL_INT_MULTIPLE: > > { > > int i; > > > >