Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

#pragma STDC CX_LIMITED_RANGE

37 views
Skip to first unread message

James R. Kuyper

unread,
Mar 22, 2018, 6:00:45 PM3/22/18
to
The C standard, section 7.3.4p2, says:
"The usual mathematical formulas for complex multiply, divide, and
absolute value are problematic because of their treatment of infinities
and because of undue overflow and underflow. The CX_LIMITED_RANGE pragma
can be used to inform the implementation that (where the state is
‘‘on’’) the usual mathematical formulas are acceptable. ..."

Example: consider (a+b*i)*(c+d*i) = (a*c-b*d) + (b*c+a*d)*i.
a*c-b*d might have a mathematical value that is representible despite
the fact that a*c overflows (if the difference is small enough, it's
pretty likely that b*d would overflow, too).
There are alternatives to "the usual mathematical formulas" which avoid
those problems. Since CX_LIMITED_RANGE is "off" by default, use of those
alternatives is normally required by the C standard, which can be a
problem, because they are significantly slower than "the usual
mathematical formulas", and many uses of complex numbers don't involve
calculations where those issues would be a problem.

Does std::complex<T> address the same issue in any way, and if so, how?

wyn...@gmail.com

unread,
Mar 23, 2018, 4:20:08 AM3/23/18
to
James R. Kuyper於 2018年3月23日星期五 UTC+8上午6時00分45秒寫道:
[The Standard C++](old) I can refer says little about std::complex except
a list of basic protocols and semantic.
CX_LIMITED_RANGE pragma seems to me is for use before the birth of cabs()
...complex functions.

James Kuyper

unread,
Mar 23, 2018, 6:31:32 AM3/23/18
to
Which version of standard C++ are you referring to as "old"? I'm
primarily interested in what it says in the current version of the
standard, which I believe is C++2017. I use, as my reference for
C++2017, n4567.pdf, which was the last freely available draft version of
the standard before it became official.
I agree that the description of <complex> in section 26.4 does not seem
to address this question at all. In particular, I could not find any
occurrence of the words "overflow" or "underflow" or the string
"infinit" anywhere in that section. However, I wanted to find out if I
had missed something that's relevant.

> CX_LIMITED_RANGE pragma seems to me is for use before the birth of cabs()
> ...complex functions.

I've no idea what you mean by that. CX_LIMITED_RANGE was added to the C
standard in C99, the same version of the standard that added full
support for complex numbers, including complex function in <math.h> such
as cabs. CX_LIMITED_RANGE applies to arithmetic operations involving
complex values, and only to such operations.

wyn...@gmail.com

unread,
Mar 23, 2018, 9:31:36 AM3/23/18
to
James Kuyper於 2018年3月23日星期五 UTC+8下午6時31分32秒寫道:
.....
I briefly checked n4859.pdf, no mention of CX_LIMITED_RANGE, nor related
things. The link might be useful:
https://stackoverflow.com/questions/42045291/does-icc-satisfy-c99-specs-for-multiplication-of-complex-numbers

James Kuyper

unread,
Mar 23, 2018, 11:29:30 AM3/23/18
to
>> had missed something that's relevant....
> I briefly checked n4859.pdf, no mention of CX_LIMITED_RANGE, nor related
> things.

Yes, I know that - checking to see whether C++ provided the same pragma
was one of the first things I did. I looked for something else in the
C++ standard that addresses the same issue that CX_LIMITED_RANGE
addresses for C. I didn't find anything, but I was hoping that someone
might point out something I'd missed.
0 new messages