public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Letu Ren <fantasquex@gmail.com>
To: libc-alpha@sourceware.org
Cc: fweimer@redhat.com, joseph@codesourcery.com, schwab@suse.de
Subject: Re: [PATCH v5] stdlib/strfrom: Add copysign to fix NAN issue on riscv (BZ #29501)
Date: Thu, 13 Oct 2022 21:02:28 +0800	[thread overview]
Message-ID: <CAEUwDuDcbkCazvB2Px=VarL1R74JZRfodL+jQg5X8B7TNdWORA@mail.gmail.com> (raw)
In-Reply-To: <20221006150137.18691-1-fantasquex@gmail.com>

> According to the specification of ISO/IEC TS 18661-1:2014,
>
> The strfromd, strfromf, and strfroml functions are equivalent to
> snprintf(s, n, format, fp) (7.21.6.5), except the format string contains only
> the character %, an optional precision that does not contain an asterisk *, and
> one of the conversion specifiers a, A, e, E, f, F, g, or G, which applies to
> the type (double, float, or long double) indicated by the function suffix
> (rather than  by a length modifier). Use of these functions with any other 20
> format string results in undefined behavior.
>
> strfromf will convert the arguement with type float to double first.
>
> According to the latest version of IEEE754 which is published in 2019,
>
> Conversion of a quiet NaN from a narrower format to a wider format in the same
> radix, and then back to the same narrower format, should not change the quiet
> NaN payload in any way except to make it canonical.
>
> When either an input or result is a NaN, this standard does not interpret the
> sign of a NaN. However, operations on bit strings—copy, negate, abs,
> copySign—specify the sign bit of a NaN result, sometimes based upon the sign
> bit of a NaN operand. The logical predicates totalOrder and isSignMinus are
> also affected by the sign bit of a NaN operand. For all other operations, this
> standard does not specify the sign bit of a NaN result, even when there is only
> one input NaN, or when the NaN is produced from an invalid operation.
>
> converting NAN or -NAN with type float to double doesn't need to keep
> the signbit. As a result, this test case isn't mandatory.
>
> The problem is that according to RISC-V ISA manual in chapter 11.3 of
> riscv-isa-20191213,
>
> Except when otherwise stated, if the result of a floating-point operation is
> NaN, it is the canonical NaN. The canonical NaN has a positive sign and all
> significand bits clear except the MSB, a.k.a. the quiet bit. For
> single-precision floating-point, this corresponds to the pattern 0x7fc00000.
>
> which means that conversion -NAN from float to double won't keep the signbit.
>
> Since glibc ought to be consistent here between types and architectures, this
> patch adds copysign to fix this problem if the string is NAN. This patch
> adds two different functions under sysdeps directory to work around the
> issue.
>
> This patch has been tested on x86_64 and riscv64.
>
> Resolves: BZ #29501
>
> v2: Change from macros to different inline functions.
> v3: Add unlikely check to isnan.
> v4: Fix wrong commit message header.
> v5: Fix style: add space before parentheses.
> Signed-off-by: Letu Ren <fantasquex@gmail.com>
> ---
> I'm not sure about copyright of the new file I created and the name of
> the new function. Please give me some advice. Thanks.

Hi, it has been almost a week since this patch was sent. I'm looking
forward to any response.

Thanks.
Letu Ren

  reply	other threads:[~2022-10-13 13:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-06 15:01 Letu Ren
2022-10-13 13:02 ` Letu Ren [this message]
2022-10-21  8:57   ` Letu Ren
2022-10-21 13:08 ` Adhemerval Zanella Netto
2022-10-21 15:01   ` Letu Ren

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='CAEUwDuDcbkCazvB2Px=VarL1R74JZRfodL+jQg5X8B7TNdWORA@mail.gmail.com' \
    --to=fantasquex@gmail.com \
    --cc=fweimer@redhat.com \
    --cc=joseph@codesourcery.com \
    --cc=libc-alpha@sourceware.org \
    --cc=schwab@suse.de \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).