* pow(3): warn against ineffecient uses?
@ 2017-03-29 19:35 Joachim Wuttke
[not found] ` <ee3b127b-5e9e-e82d-1731-172185c8ebd2-97/bSmCnXvjoK6nBLMlh1Q@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Joachim Wuttke @ 2017-03-29 19:35 UTC (permalink / raw)
To: linux-man-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 560 bytes --]
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).
My motivation for this proposal comes from student code
in which I have seen exactly these mistakes.
- Joachim
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5110 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread[parent not found: <ee3b127b-5e9e-e82d-1731-172185c8ebd2-97/bSmCnXvjoK6nBLMlh1Q@public.gmane.org>]
* Re: pow(3): warn against ineffecient uses? [not found] ` <ee3b127b-5e9e-e82d-1731-172185c8ebd2-97/bSmCnXvjoK6nBLMlh1Q@public.gmane.org> @ 2017-03-31 11:17 ` Florian Weimer [not found] ` <871stdn197.fsf-ZqZwdwZz9NfTBotR3TxKnbNAH6kLmebB@public.gmane.org> 0 siblings, 1 reply; 3+ messages in thread From: Florian Weimer @ 2017-03-31 11:17 UTC (permalink / raw) To: Joachim Wuttke; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA * 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 ^ permalink raw reply [flat|nested] 3+ messages in thread
[parent not found: <871stdn197.fsf-ZqZwdwZz9NfTBotR3TxKnbNAH6kLmebB@public.gmane.org>]
* Re: pow(3): warn against ineffecient uses? [not found] ` <871stdn197.fsf-ZqZwdwZz9NfTBotR3TxKnbNAH6kLmebB@public.gmane.org> @ 2017-04-10 12:13 ` Michael Kerrisk (man-pages) 0 siblings, 0 replies; 3+ messages in thread From: Michael Kerrisk (man-pages) @ 2017-04-10 12:13 UTC (permalink / raw) To: Florian Weimer, Joachim Wuttke Cc: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w, linux-man-u79uwXL29TY76Z2rM5mHXA On 03/31/2017 01:17 PM, Florian Weimer wrote: > * 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). Thanks, Florian, for jumping in on this. I don't have enough knowledge of these details, so your comments help a lot. Lacking any further refinement, I'll drop this proposed change for now. Cheers, Michael -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/ -- 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 ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-04-10 12:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
[not found] ` <871stdn197.fsf-ZqZwdwZz9NfTBotR3TxKnbNAH6kLmebB@public.gmane.org>
2017-04-10 12:13 ` Michael Kerrisk (man-pages)
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox