Hi Damian,
I don't have a Chapel-specific answer and floating-point computations are
not my general area of work, however, a couple years ago I attended the
PLDI conference and was really impressed with the paper and presentation
for Automatically Improving Accuracy for Floating Point Expressions
<https://pldi15.sigplan.org/event/pldi2015-papers-automatically-improving-accuracy-for-floating-point-expressions>,
which was selected as a Distinguished Paper.
In that work, the authors developed a tool, Herbie
<https://herbie.uwplse.org/>, that was also incorporated into a web-based
demo <https://herbie.uwplse.org/demo/>. Herbie doesn't support the
less-than operator, but I tried two variants (sqrt(2) * 0.5 - abs(x)
<https://herbie.uwplse.org/demo/87f4661972ce0de7e5c35b3c2a87dc63d81af76e.fe217c86e8caf66aab2a65bdea46a7a3f9f1de32/graph.html>)
and (0.5 - x * x
<https://herbie.uwplse.org/demo/fc5f3084ce9013dc371705d8a085341d7f76776f.fe217c86e8caf66aab2a65bdea46a7a3f9f1de32/graph.html>).
If I interpret their output correctly, neither has accuracy issues.
On the performance side, I thought I'd check what assembly those two
variants generate using Matt Godbolt's Compiler Explorer
<https://godbolt.org/g/3B1Fw4>. With "-O3" and "-ffast-math" flags set, the
results are quite similar between Clang 5 and GCC 7.2.
All that said, I'm no expert in floating point accuracy or performance, so
take this simply as observations from a curious reader.
Of the two, I think "x * x < 0.5" looks more readable.
Thanks,
Nick
On Wed, Oct 18, 2017 at 1:17 AM, Damian McGuckin <[email protected]> wrote:
>
> Hi All,
>
> Given a number
>
> m : real(?w) where w = 32, 64, 128???
>
> and
> half = 0.5:real(w)
>
> say, I want to know whether
>
> abs(m) < sqrt(2.0:real(w)) * 0.5:real(w)
>
> Using a number accurate to 40 decimal places, I could write
>
> const sqrtTwo = 1.4142135623730950488016887242
> 096980785696:real(w);
>
> If I rely on the truncation error of the compiler as it approximates that
> constant (originally accurate to 40 places) to w binary digits, I use
>
> abs(m) < sqrtTwo * Half
>
> and I know that the multiplication on the right does not damage accuracy.
>
> I could rely on the truncation error of the multiplication to just do
>
> m * m < half // nominally the same
>
> Am I going to sacrifice accuracy for portability by using the latter?
>
> What looks more readable?
>
> Regards - Damian
>
> Pacific Engineering Systems International, 277-279 Broadway, Glebe NSW 2037
> Ph:+61-2-8571-0847 .. Fx:+61-2-9692-9623 | unsolicited email not wanted
> here
> Views & opinions here are mine and not those of any past or present
> employer
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Chapel-developers mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/chapel-developers
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Chapel-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-developers