Topic: floating-point status flags and C++ exceptions
Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@googlemail.com>
Date: Thu, 10 Mar 2011 10:22:26 CST Raw View
[Second sending attempt after 6 days]
On 2011-03-04 10:15, Al Grant wrote:
>
> Standard C [7.13.2.1] is explicit that floating-point status flags
> must be preserved by longjmp() and not reverted to what they
> were at the time of setjmp(). Is there any equivalent guarantee
> in C++ about the status flags when an exception is thrown?
>
> (I realise<fenv.h> wasn't around in time to be incorporated by
> reference in C++98, but access to the FP environment is pretty
> fundamental to numeric programming and I would have hoped
> that some time in the last decade someone would have said
> whatever needed to be said to do it predictably in C++.)
There is no such guarantee, but there is a guarantee that the
floating-point environment is hold per thread, see [cfenv.syn]
p. 3+4:
3 The floating-point environment has thread storage duration (3.7.2).
The initial state for a thread s floatingpoint environment is the
state of the floating-point environment of the thread that constructs
the corresponding std::thread object (30.3.1) at the time it
constructed the object. [ Note: That is, the child thread gets the
floating-point state of the parent thread at the time of the child s
creation. end note ]
4 A separate floating-point environment shall be maintained for each
thread. Each function accesses the environment corresponding to its
calling thread.
I don't see any reason why exceptions should have a special rule as
you refer to. I don't think that the *jmp functions can be directly
compared to exceptions in this regard. Could you elaborate which
problems you are envisioning if exceptions miss to do that? A code
example would be helpful.
Thanks & Greetings from Bremen,
Daniel Kr gler
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Al Grant <algrant@myrealbox.com>
Date: Fri, 4 Mar 2011 03:15:12 CST Raw View
Standard C [7.13.2.1] is explicit that floating-point status flags
must be preserved by longjmp() and not reverted to what they
were at the time of setjmp(). Is there any equivalent guarantee
in C++ about the status flags when an exception is thrown?
(I realise <fenv.h> wasn't around in time to be incorporated by
reference in C++98, but access to the FP environment is pretty
fundamental to numeric programming and I would have hoped
that some time in the last decade someone would have said
whatever needed to be said to do it predictably in C++.)
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]