Yes, with a thread-local storage. That’s true not just for rounding modes, but for FPE exceptions/status flags as well.
I don’t see it in your example, but I think I understood you correctly. Yes, it’s expected that all code in the new context will work with same altered settings for FPE. E.g. not raise exceptions for certain cases or use some non-default rounding mode.
IIUIC, they are trying to make rounding more “local”, i.e. some per-function setting. Perhaps, it’s more close to Oscar’s proposal to have mathematical functions (like sin or add) on the context object.
I’m not aware of any proposal to replace fset/getround() in C, though the c comitee is a strange place nowadays and did strange things for floating-point math in C.
Really?
>>> FE_TONEAREST, FE_UPWARD = 0, 0x800 # magic number might be different on your system
>>> import ctypes, math
>>> libm = ctypes.CDLL('libm.so.6')
>>> libm.fesetround.argtypes = [ctypes.c_int]
>>> libm.fesetround.restype = ctypes.c_int
>>> libm.fesetround(FE_TONEAREST)
0
>>> math.log(123)
4.812184355372417
>>> libm.fesetround(FE_UPWARD)
0
>>> math.log(123)
4.812184355372418