Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Miles Bader Newsgroups: comp.lang.c++ Subject: Re: Writing efficient normal distribution function (for learning purposes). Date: Mon, 20 Feb 2012 19:57:20 +0900 Organization: NEC Electronics Lines: 39 Message-ID: References: <5969204.9.1329493277515.JavaMail.geo-discussion-forums@vbnd9> <712803.2037.1329645562216.JavaMail.geo-discussion-forums@vbfm8> <27450340.18.1329648569770.JavaMail.geo-discussion-forums@vbpw21> <87r4xqzzgy.fsf@catnip.gol.com> <67abe3b8-4dbf-445d-bda9-d51864fe9584@pq6g2000pbc.googlegroups.com> <4f421f54$0$2815$7b1e8fa0@news.nbl.fi> Mime-Version: 1.0 Content-Type: text/plain X-Trace: individual.net qbwHaGTbTBftVquupMnAQQlXqMPhsCIc5LJmIPc8x0kkhNtdAQ Cancel-Lock: sha1:qeIbOv19el/BILekjJvLwNHejwk= sha1:TSK7C2akVTiDzSqzs6WLGmjnTP8= System-Type: x86_64-unknown-linux-gnu Blat: Foop Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:14319 Juha Nieminen writes: >> And >> possibly -ffast-math if the OP is happy with imprecise (aka wrong) >> results. > > How are the results imprecise/wrong when using -ffast-math? > > Granted, I don't know every single detail, but I have the impression > that what it does is that it skips some of the most pedantic rules of > IEEE floating point math in favor of faster code. These minute pedantic > rules do not affect the accuracy of the end result in any significant > way (more than what can be expected from floating point values anyways). It's not that -ffast-math is bad or anything (I use it happily myself), but if precise results are important it's a good idea to check what it does in detail, and make sure things are OK. One can always, of course, use -ffast-math, and then _disable_ some of the finer-grained options it enabled. For instance: -ffast-math enables -funsafe-math-optimizations, which enables -freciprocal-math, which: "Allows the reciprocal of a value to be used instead of dividing by the value if this enables optimizations ... Note that this loses precision and increases the number of flops operating on the value." -funsafe-math-optimizations also enables fassociative-math, and changing the order of operations can affect the precision of the result in a way that the programmer didn't expect. -ffast-math also enables -ffinite-math-only, which of course will cause infinities etc to not be handled as expected. etc. -miles -- `There are more things in heaven and earth, Horatio, Than are dreamt of in your philosophy.'