[J3] C TS 18661
Van Snyder
Van.Snyder at jpl.nasa.gov
Tue Jan 29 21:15:19 EST 2019
Steve Kargl drew our attention to C TS 18661, WG14/n1950.
This TS adds trigonometric intrinsics sin(pi*x) etc, and their inverses.
We are pondering whether to add degree intrinsics, which might be more
useful, especially for engineering applications, as the arguments are
more likely to be exactly representable as floating-point numbers. For
example, sine of 30 degrees would be SIND(30.0), or SINPI(1.0/6.0). We
should consider their inverses too (including atan2). Complex doesn't
make sense for these.
It also adds functions expm1(x) and logp1(x) (with a synonym log1p).
These compute exp(x-1) and log(x+1). These appear frequently in
scientific and engineering applications, and have much better round-off
characteristics for small x. I proposed these in 04-184r1. Complex
makes sense for these. log10p1 might be a bridge too far.
It also adds rsqrt(x), which computes 1/sqrt(x). sqrt(x) appears
frequently as the denominator of expressions in scientific and
engineering applications. Computing rsqrt(x) is faster than computing
sqrt(x) and then dividing. Computing sqrt(x) from rsqrt(x) and
multiplying by x is faster than sqrt(x). X86 has an rsqrt(x)
instruction in SSE. There is a very fast algorithm, that first appeared
as part of the "Quake" game, but nobody understands exactly how it
works. Steve pointed out the X86 SSE instruction is only available for
single precision, and only gets 11 correct bits, but two Newton
iterations give full single precision, and three give double precision.
The Newton iteration for rsqrt involves only multiplies, not divides.
The manual that was referenced in some web page (of which I've lost
track) says rsqrt is about as fast as multiply, while sqrt is about as
slow as divide.
In addition to degree intrinsics, does J3 care to consider adding any of
these functions?
acosd
asind
atand
atan2d
expm1
logp1 (or log1p)
rsqrt
Giving the perception of "lagging behind" C/C++ on mathematical
intrinsic functions is probably not good advertising for Fortran.
More information about the J3
mailing list