From: David Laight <david.laight.linux@gmail.com>
To: "Ivan A. Melnikov" <iv@altlinux.org>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Jonathan Cameron" <Jonathan.Cameron@huawei.com>,
"Francesco Lavra" <flavra@baylibre.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: tools: Use proper macro to detect _Float16 support
Date: Mon, 28 Sep 2026 10:05:06 +0100 [thread overview]
Message-ID: <20260928100506.7ba18d8b@pumpkin> (raw)
In-Reply-To: <20260918161305.1161852-1-iv@altlinux.org>
On Fri, 18 Sep 2026 20:13:02 +0400
"Ivan A. Melnikov" <iv@altlinux.org> wrote:
> __FLT16_MAX__ is an internal compiler macro. GCC defines it if
> _Float16 is supported by the target in general, but the support
> may depend on the exact target options. For example, on i586
> without -msse2 I get the following error from GCC15:
>
> iio_generic_buffer.c: In function 'print2byte':
> iio_generic_buffer.c:141:17: error: invalid conversion from type '_Float16' without option '-msse2'
> 141 | printf("%05f ", ((float)converter.f + info->offset) * info->scale);
> | ^~~~~~
>
> To fix that, use the public macro without double underscores.
Assuming float and _Float16 are both IEEE 754 you can directly convert them.
If I've typed it correctly:
union {
uint32_t u;
float f;
} converter;
converter.u = (input & 0x8000) << 16 | (input & 0x7fff) << 13;
printf(... converter.f * 0x1p112 ...)
That handles denormalised values (near zero) but not infinity and NaN.
David
>
> Fixes: cdd445d4b2a9 ("iio: tools: Add support for floating-point types in buffer scan elements")
> Signed-off-by: Ivan A. Melnikov <iv@altlinux.org>
> ---
> tools/iio/iio_generic_buffer.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/iio/iio_generic_buffer.c b/tools/iio/iio_generic_buffer.c
> index 000193612aad..9ea93984e0e9 100644
> --- a/tools/iio/iio_generic_buffer.c
> +++ b/tools/iio/iio_generic_buffer.c
> @@ -131,7 +131,7 @@ static void print2byte(uint16_t input, struct iio_channel_info *info)
> printf("%05f ", ((float)input + info->offset) * info->scale);
> break;
> case 'f': {
> -#if defined(__FLT16_MAX__)
> +#if defined(FLT16_MAX)
> union {
> uint16_t u;
> _Float16 f;
prev parent reply other threads:[~2026-09-28 9:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-18 16:13 Ivan A. Melnikov
2026-09-19 9:39 ` Joshua Crofts
2026-09-21 11:33 ` Ivan A. Melnikov
2026-09-27 20:54 ` Jonathan Cameron
2026-09-19 14:04 ` Andy Shevchenko
2026-09-28 9:05 ` David Laight [this message]
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=20260928100506.7ba18d8b@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=flavra@baylibre.com \
--cc=iv@altlinux.org \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®