public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
From: Florian Weimer <fw-d32yF4oPJVt0XxTmqZlbVQ@public.gmane.org>
To: Joachim Wuttke <j.wuttke-97/bSmCnXvjoK6nBLMlh1Q@public.gmane.org>
Cc: linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: pow(3): warn against ineffecient uses?
Date: Fri, 31 Mar 2017 13:17:56 +0200	[thread overview]
Message-ID: <871stdn197.fsf@mid.deneb.enyo.de> (raw)
In-Reply-To: <ee3b127b-5e9e-e82d-1731-172185c8ebd2-97/bSmCnXvjoK6nBLMlh1Q@public.gmane.org> (Joachim Wuttke's message of "Wed, 29 Mar 2017 21:35:07 +0200")

* Joachim Wuttke:

> Maybe it would be appropriate to warn against inefficient
> uses of the function pow. To make a very first proposal
> for a paragraph to be added to pow(3):
>
> In time-critical code, pow with small integer or simple
> fractional exponents should be avoided in favor of
> straightforward multiplication, division or square or
> cubic roots: prefer x*x over pow(x,2), 1/x over pow(x,-1),
> sqrt(x) over pow(x,0.5), or cbrt(x*x) over pow(x,2.0/3).

I don't think transforming pow (x, 2.0 / 3) to cbrt (x * x) is correct
because the result is not correctly rounded.  I'm not sure if it is a
good idea to add those examples to the manual page without discussing
the cases where the transformations might not be valid.

If GCC does not handle some of the common cases from real-world code,
that could be fixed in GCC (and GCC can do more transformations under
-ffast-math, too).
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2017-03-31 11:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-29 19:35 pow(3): warn against ineffecient uses? Joachim Wuttke
     [not found] ` <ee3b127b-5e9e-e82d-1731-172185c8ebd2-97/bSmCnXvjoK6nBLMlh1Q@public.gmane.org>
2017-03-31 11:17   ` Florian Weimer [this message]
     [not found]     ` <871stdn197.fsf-ZqZwdwZz9NfTBotR3TxKnbNAH6kLmebB@public.gmane.org>
2017-04-10 12:13       ` Michael Kerrisk (man-pages)

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=871stdn197.fsf@mid.deneb.enyo.de \
    --to=fw-d32yf4opjvt0xxtmqzlbvq@public.gmane.org \
    --cc=j.wuttke-97/bSmCnXvjoK6nBLMlh1Q@public.gmane.org \
    --cc=linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /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